113622024-08-26 01:44:21kukkermanOsztozkodás (75 pont)cpp17Accepted 75/7563ms1648 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

void beolvas(std::istream &be, std::vector<int> &a, int &k) {
    int n;
    be >> n >> k;

    a.resize(n);
    for (auto &e : a) {
        be >> e;
    }
}

void feldolgoz(std::vector<int> &a, int k) {
    const auto n = static_cast<int>(a.size());

    sort(a.begin(), a.end());

    std::vector<int64_t> bal_osszeg(n);
    bal_osszeg[0] = a[0];
    for (int i = 1; i < n; i++) {
        bal_osszeg[i] += bal_osszeg[i - 1] + a[i];
    }

    int64_t pontok[2] = { 0, 0 };
    int j = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i < k && a[i] < bal_osszeg[i]) {
            pontok[j] += bal_osszeg[i];
            break;
        }

        pontok[j] += a[i];
        j = 1 - j;
    }

    std::cout << pontok[0] << ' ' << pontok[1] << '\n';
}

int main() {
    std::vector<int> a;
    int k;
    beolvas(std::cin, a, k);

    feldolgoz(a, k);

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/02ms360 KiB
2Accepted0/02ms360 KiB
3Accepted2/22ms360 KiB
4Accepted3/33ms384 KiB
5Accepted3/32ms384 KiB
6Accepted2/24ms360 KiB
7Accepted3/34ms376 KiB
8Accepted2/24ms360 KiB
9Accepted3/34ms360 KiB
10Accepted2/24ms496 KiB
11Accepted3/34ms376 KiB
12Accepted1/159ms1512 KiB
13Accepted2/259ms1444 KiB
14Accepted1/159ms1512 KiB
15Accepted2/259ms1648 KiB
16Accepted1/135ms1448 KiB
17Accepted2/243ms1644 KiB
18Accepted1/135ms1512 KiB
19Accepted2/229ms1512 KiB
20Accepted2/228ms1564 KiB
21Accepted3/348ms1436 KiB
22Accepted2/241ms1440 KiB
23Accepted3/345ms1512 KiB
24Accepted2/248ms1436 KiB
25Accepted3/350ms1552 KiB
26Accepted2/248ms1532 KiB
27Accepted3/363ms1440 KiB
28Accepted2/263ms1584 KiB
29Accepted3/361ms1536 KiB
30Accepted3/32ms232 KiB
31Accepted3/32ms360 KiB
32Accepted3/33ms384 KiB
33Accepted3/32ms504 KiB
34Accepted3/32ms376 KiB