113602024-08-26 00:16:42kukkermanOsztozkodás (75 pont)cpp17Wrong answer 27/7561ms2024 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());

    int bal, ossz = 0;
    for (bal = 0; bal < n && ossz <= 0; bal++) {
        ossz += a[bal];
    }

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

    int anna = 0;
    if (bal > k) {
        for (int i = n - 1; i >= 0; i -= 2) {
            anna += a[i];
        }

    } else {
        int i;
        for (i = n - 1; i >= k; i -= 2) {
            anna += a[i];
        }

        if (i == k - 1) {
            for (; i >= 0; i--) {
                anna += a[i];
            }
        }
    }

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

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

    feldolgoz(a, k);

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base27/75
1Accepted0/03ms428 KiB
2Accepted0/02ms360 KiB
3Accepted2/23ms496 KiB
4Accepted3/33ms528 KiB
5Accepted3/32ms360 KiB
6Wrong answer0/24ms632 KiB
7Wrong answer0/34ms360 KiB
8Wrong answer0/24ms360 KiB
9Wrong answer0/34ms360 KiB
10Wrong answer0/24ms504 KiB
11Wrong answer0/34ms360 KiB
12Wrong answer0/159ms1572 KiB
13Wrong answer0/259ms1572 KiB
14Wrong answer0/159ms1768 KiB
15Wrong answer0/257ms1580 KiB
16Accepted1/135ms1256 KiB
17Accepted2/243ms1412 KiB
18Accepted1/134ms1292 KiB
19Accepted2/228ms1128 KiB
20Accepted2/228ms1076 KiB
21Wrong answer0/348ms1656 KiB
22Accepted2/241ms1532 KiB
23Wrong answer0/345ms1408 KiB
24Wrong answer0/248ms1432 KiB
25Wrong answer0/348ms1528 KiB
26Wrong answer0/248ms1356 KiB
27Wrong answer0/361ms2024 KiB
28Wrong answer0/261ms1896 KiB
29Wrong answer0/359ms1768 KiB
30Accepted3/33ms360 KiB
31Accepted3/33ms360 KiB
32Accepted3/32ms376 KiB
33Wrong answer0/32ms360 KiB
34Wrong answer0/32ms360 KiB