113302024-08-11 22:58:52kukkermanDarabolás (50 pont)cpp17Accepted 50/5079ms2148 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

void beolvas(std::istream &be, int &m, int &n, std::vector<int> &vkoltseg, std::vector<int> &fkoltseg) {
    be >> m >> n;

    vkoltseg.resize(m - 1);
    for (auto &k : vkoltseg) {
        be >> k;
    }

    fkoltseg.resize(n - 1);
    for (auto &k : fkoltseg) {
        be >> k;
    }
}

uint64_t feldolgoz(int m, int n, std::vector<int> &vkoltseg, std::vector<int> &fkoltseg) {
    sort(vkoltseg.begin(), vkoltseg.end(), std::greater<int>());
    sort(fkoltseg.begin(), fkoltseg.end(), std::greater<int>());

    uint64_t ossz_koltseg = 0;
    int v = 0, f = 0;
    while (v < m - 1 && f < n - 1) {
        if (vkoltseg[v] < fkoltseg[f]) {
            ossz_koltseg += fkoltseg[f] * (v + 1);
            f++;

        } else {
            ossz_koltseg += vkoltseg[v] * (f + 1);
            v++;
        }
    }

    for (; v < m - 1; v++) {
        ossz_koltseg += vkoltseg[v] * n;
    }

    for (; f < n - 1; f++) {
        ossz_koltseg += fkoltseg[f] * m;
    }

    return ossz_koltseg;
}

int main() {
    int m, n;
    std::vector<int> vkoltseg, fkoltseg;
    beolvas(std::cin, m, n, vkoltseg, fkoltseg);

    std::cout << feldolgoz(m, n, vkoltseg, fkoltseg) << '\n';

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms500 KiB
2Accepted0/045ms1380 KiB
3Accepted1/13ms428 KiB
4Accepted1/13ms356 KiB
5Accepted1/13ms356 KiB
6Accepted1/13ms356 KiB
7Accepted1/13ms356 KiB
8Accepted1/13ms632 KiB
9Accepted1/13ms632 KiB
10Accepted1/13ms356 KiB
11Accepted1/13ms356 KiB
12Accepted1/13ms504 KiB
13Accepted1/13ms376 KiB
14Accepted1/13ms356 KiB
15Accepted1/13ms364 KiB
16Accepted1/13ms548 KiB
17Accepted1/13ms504 KiB
18Accepted1/13ms504 KiB
19Accepted2/23ms504 KiB
20Accepted2/23ms632 KiB
21Accepted3/36ms416 KiB
22Accepted3/39ms564 KiB
23Accepted4/424ms888 KiB
24Accepted4/425ms788 KiB
25Accepted4/445ms1380 KiB
26Accepted4/446ms1380 KiB
27Accepted4/479ms2020 KiB
28Accepted4/479ms2148 KiB