113652024-08-27 00:50:12kukkermanOsztozkodás (75 pont)cpp17Accepted 75/7561ms1384 KiB
#include <iostream>
#include <vector>
#include <algorithm>

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());

    long long opt = 0, ossz = 0;
    for (int i = 0; i < k; i++) {
        ossz += a[i];
        opt = std::max(ossz - opt, ossz);
    }

    for (int i = k; i < n; i++) {
        ossz += a[i];
        opt = ossz - opt;
    }

    std::cout << opt << ' ' << ossz - opt << '\n';
}

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

    feldolgoz(a, k);

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/02ms432 KiB
2Accepted0/03ms300 KiB
3Accepted2/22ms404 KiB
4Accepted3/33ms396 KiB
5Accepted3/32ms384 KiB
6Accepted2/24ms360 KiB
7Accepted3/34ms632 KiB
8Accepted2/24ms232 KiB
9Accepted3/34ms232 KiB
10Accepted2/24ms632 KiB
11Accepted3/34ms488 KiB
12Accepted1/159ms1180 KiB
13Accepted2/257ms1052 KiB
14Accepted1/159ms1128 KiB
15Accepted2/259ms1144 KiB
16Accepted1/134ms1128 KiB
17Accepted2/243ms1256 KiB
18Accepted1/135ms1184 KiB
19Accepted2/228ms1272 KiB
20Accepted2/228ms1052 KiB
21Accepted3/348ms1272 KiB
22Accepted2/239ms1168 KiB
23Accepted3/345ms1384 KiB
24Accepted2/248ms1072 KiB
25Accepted3/348ms1272 KiB
26Accepted2/248ms1196 KiB
27Accepted3/361ms1196 KiB
28Accepted2/261ms1128 KiB
29Accepted3/359ms1128 KiB
30Accepted3/33ms504 KiB
31Accepted3/33ms384 KiB
32Accepted3/32ms360 KiB
33Accepted3/32ms360 KiB
34Accepted3/32ms504 KiB