247912026-02-15 11:22:51ubormaciDarabolás (50 pont)cpp17Elfogadva 50/5059ms5096 KiB
#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

std::lcm(ll a, ll b), std::gcd(int a, int b)

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

void solve() {

	ll n, m;
	cin >> n >> m;

	// olyan szamok erdekelnek, amik n-et es m-et is osztjak
	// mert akkora negyzetekre lehet felosztani
	// minden ilyen osztora megnezzuk mennyibe kerul
	// es ezeknek a minimuma
	// pikk-pakk

	vector<ll> row(n+1, 0);
	vector<ll> col(m+1, 0);

	vector<pair<ll,ll>> g(n+m-2, {0,0}); // cost, index
	
	ll ft = 1e7;
	ll j = 0;

	for(ll i = 1; i < n; i++) {
		cin >> row[i];
		g[j] = {row[i], i};
		j++;
	}
	for(ll i = 1; i < m; i++) {
		cin >> col[i];
		g[j] = {col[i], i + ft};
		j++;
	}

	ll ans = 0;

	ll rowcut = 0;
	ll horcut = 0;

	sort(g.rbegin(), g.rend());
	for(const auto & [w, ind] : g) {
		
		bool row = true;

		ll i = ind;

		if(ind > ft) {
			row = false;
			// -> col
			i -= ft;
		}

		if(row) {

			// we're doing an operation at rows
			// so we look at horizontal cuts
			ans += w * (horcut+1);
			rowcut++;
		}else{
			ans += w * (rowcut+1);
			horcut++;
		}
	}

	cout << ans;
	
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	solve();

	return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/032ms2868 KiB
3Elfogadva1/11ms508 KiB
4Elfogadva1/12ms316 KiB
5Elfogadva1/11ms316 KiB
6Elfogadva1/11ms316 KiB
7Elfogadva1/11ms316 KiB
8Elfogadva1/11ms316 KiB
9Elfogadva1/11ms316 KiB
10Elfogadva1/11ms316 KiB
11Elfogadva1/11ms376 KiB
12Elfogadva1/11ms316 KiB
13Elfogadva1/11ms560 KiB
14Elfogadva1/11ms316 KiB
15Elfogadva1/11ms316 KiB
16Elfogadva1/11ms316 KiB
17Elfogadva1/11ms316 KiB
18Elfogadva1/11ms316 KiB
19Elfogadva2/21ms316 KiB
20Elfogadva2/21ms508 KiB
21Elfogadva3/33ms564 KiB
22Elfogadva3/36ms888 KiB
23Elfogadva4/416ms1588 KiB
24Elfogadva4/414ms1512 KiB
25Elfogadva4/430ms2868 KiB
26Elfogadva4/430ms2976 KiB
27Elfogadva4/457ms4916 KiB
28Elfogadva4/459ms5096 KiB