232872026-01-18 15:00:01miszorimarciDarabolás (50 pont)cpp17Accepted 50/5039ms2004 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int m, n;cin >> m >> n;

    vector<long long> h(m - 1), v(n - 1);

    for (int i = 0; i < m - 1; i++) cin >> h[i];
    for (int i = 0; i < n - 1; i++) cin >> v[i];

    sort(h.begin(), h.end(), greater<long long>());
    sort(v.begin(), v.end(), greater<long long>());

    long long hp = 1, vp = 1, ans = 0;
    int i = 0, j = 0;

    while (i < h.size() || j < v.size()) {
        if (j == v.size() || (i < h.size() && h[i] > v[j])) {
            ans += h[i] * vp;
            hp++;
            i++;
        } else {
            ans += v[j] * hp;
            vp++;
            j++;
        }
    }

    cout << ans << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/021ms1260 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms508 KiB
7Accepted1/11ms316 KiB
8Accepted1/11ms316 KiB
9Accepted1/11ms316 KiB
10Accepted1/11ms508 KiB
11Accepted1/11ms500 KiB
12Accepted1/11ms316 KiB
13Accepted1/11ms316 KiB
14Accepted1/11ms316 KiB
15Accepted1/11ms500 KiB
16Accepted1/11ms316 KiB
17Accepted1/11ms316 KiB
18Accepted1/11ms316 KiB
19Accepted2/21ms316 KiB
20Accepted2/21ms316 KiB
21Accepted3/33ms316 KiB
22Accepted3/34ms564 KiB
23Accepted4/410ms840 KiB
24Accepted4/410ms820 KiB
25Accepted4/421ms1204 KiB
26Accepted4/421ms1076 KiB
27Accepted4/439ms1856 KiB
28Accepted4/439ms2004 KiB