115182024-10-16 20:27:25chucknorrisDarabolás (50 pont)cpp17Accepted 50/5078ms2116 KiB
#include <bits/stdc++.h>

using namespace std;

int N, M;
int ver[100002], hor[100002];

int main(){
    cin >> N >> M;
    for(int i = 1; i < N; i++) cin >> ver[i];

    for(int i = 1; i < M; i++) cin >> hor[i];


    sort(ver + 1, ver + N, greater<int>());
    sort(hor + 1, hor + M, greater<int>());

    long long ans = 0;
    int vdb = 0, hdb = 0;

    int i = 1, j = 1;
    while(i <= N - 1 and j <= M - 1){
        if(ver[i] > hor[j]){
            ans = ans + 1LL * (hdb + 1) * ver[i];
            i = i + 1;
            vdb = vdb + 1;
        }
        else{
            ans = ans + 1LL * (vdb + 1) * hor[j];
            j = j + 1;
            hdb = hdb + 1;
        }
    }

    for(int k = i; k < N; k++){
        ans = ans + 1LL * (hdb + 1) * ver[k];
    }

    for(int k = j; k < M; k++){
        ans = ans + 1LL * (vdb + 1) * hor[k];
    }

    cout << ans;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms412 KiB
2Accepted0/043ms1332 KiB
3Accepted1/11ms320 KiB
4Accepted1/11ms508 KiB
5Accepted1/11ms320 KiB
6Accepted1/11ms320 KiB
7Accepted1/11ms320 KiB
8Accepted1/11ms320 KiB
9Accepted1/11ms320 KiB
10Accepted1/11ms320 KiB
11Accepted1/11ms320 KiB
12Accepted1/11ms324 KiB
13Accepted1/11ms320 KiB
14Accepted1/11ms320 KiB
15Accepted1/11ms320 KiB
16Accepted1/11ms320 KiB
17Accepted1/12ms320 KiB
18Accepted1/12ms500 KiB
19Accepted2/22ms324 KiB
20Accepted2/22ms328 KiB
21Accepted3/34ms488 KiB
22Accepted3/38ms580 KiB
23Accepted4/421ms908 KiB
24Accepted4/421ms836 KiB
25Accepted4/443ms1292 KiB
26Accepted4/443ms1160 KiB
27Accepted4/478ms2116 KiB
28Accepted4/478ms2116 KiB