153062025-02-18 09:45:18tamasnagyDarabolás (50 pont)cpp17Accepted 50/5072ms1160 KiB
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
void bevekt(int a[], int n) {
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i];
    }
}
void rendezvekt(int a[], int n) {
    for (int i = 0; i < n - 2; i++) {
        for (int j = i+1; j < n-1; j++) {
            if (a[i] < a[j]) {
                swap(a[i], a[j]);
            }
        }
    }
}
void solve(int a[], int b[], int n, int m) {
    int i = 0, j = 0;
    long long int s = 0;
    while (!(i == n - 1 && j == m - 1)) {
        if (a[i] > b[j]) {
            s += a[i] * (j+1);
            i++;
        }
        else {
            s += b[j] * (i+1);
            j++;
        }
    }
    cout << s;
}
int a[100002];
int b[100002];
int main()
{
    int n, m;
    cin >> n >> m;
    bevekt(a, n);
    bevekt(b, m);
    a[n - 1] = 0;
    b[m - 1] = 0;
    sort(a, a + n - 1, greater<int>());
    sort(b, b + m - 1, greater<int>());
    /*rendezvekt(a, n);
    rendezvekt(b, m);*/
    solve(a, b, n, m);
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms316 KiB
2Accepted0/041ms672 KiB
3Accepted1/11ms316 KiB
4Accepted1/11ms316 KiB
5Accepted1/11ms316 KiB
6Accepted1/11ms316 KiB
7Accepted1/11ms316 KiB
8Accepted1/11ms316 KiB
9Accepted1/11ms316 KiB
10Accepted1/11ms316 KiB
11Accepted1/11ms316 KiB
12Accepted1/11ms316 KiB
13Accepted1/11ms316 KiB
14Accepted1/11ms316 KiB
15Accepted1/11ms316 KiB
16Accepted1/11ms316 KiB
17Accepted1/12ms500 KiB
18Accepted1/12ms408 KiB
19Accepted2/22ms424 KiB
20Accepted2/22ms316 KiB
21Accepted3/34ms440 KiB
22Accepted3/38ms488 KiB
23Accepted4/420ms620 KiB
24Accepted4/420ms508 KiB
25Accepted4/441ms824 KiB
26Accepted4/439ms588 KiB
27Accepted4/472ms1076 KiB
28Accepted4/472ms1160 KiB