145102025-01-13 08:55:04RRoliDarabolás (50 pont)cpp17Accepted 50/5075ms1200 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int m, n;
	cin >> m >> n;
	m--; n--;
	vector<int> sor(m), osz(n);
	for(int i = 0; i < m; i++) cin >> sor[i];
	for(int i = 0; i < n; i++) cin >> osz[i];

	sort(sor.begin(), sor.end());
	sort(osz.begin(), osz.end());

	long long ossz = 0, s = m-1, o = n-1;
	while(s >= 0 || o >= 0) {
		if(o < 0 || (s >= 0 && sor[s] >= osz[o])) {
			ossz += sor[s]*(n-o);
			s--;
		} else {
			ossz += osz[o]*(m-s);
			o--;
		}
	}
	cout << ossz;

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/041ms820 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms532 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms316 KiB
8Accepted1/11ms316 KiB
9Accepted1/11ms316 KiB
10Accepted1/11ms316 KiB
11Accepted1/11ms508 KiB
12Accepted1/11ms316 KiB
13Accepted1/11ms316 KiB
14Accepted1/11ms316 KiB
15Accepted1/11ms316 KiB
16Accepted1/11ms552 KiB
17Accepted1/12ms316 KiB
18Accepted1/12ms556 KiB
19Accepted2/22ms316 KiB
20Accepted2/22ms404 KiB
21Accepted3/34ms440 KiB
22Accepted3/38ms480 KiB
23Accepted4/421ms564 KiB
24Accepted4/421ms564 KiB
25Accepted4/441ms820 KiB
26Accepted4/441ms840 KiB
27Accepted4/475ms1200 KiB
28Accepted4/475ms1192 KiB