103962024-04-01 19:04:02MagyarKendeSZLGOsztozkodás (75 pont)cpp17Accepted 75/7561ms20652 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> v(N), ps(N);
    for (ll& x : v) cin >> x;
    sort(v.begin(), v.end());

    ps[0] = v[0];
    for (int i = 1; i < N; i++) {
        ps[i] = ps[i - 1] + v[i];
    }

    array<ll, 2> playerS {0, 0};

    bool turn = 0;

    for (int i = v.size() - 1; i >= 0; i--) {
        if (i + 1 <= K && v[i] < ps[i]) {
            playerS[turn] += ps[i];
            break;
        }

        playerS[turn] += v[i];

        turn ^= 1;
    }

    cout << playerS[0] << " " << playerS[1];
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1808 KiB
2Accepted0/03ms2056 KiB
3Accepted2/23ms2272 KiB
4Accepted3/33ms2476 KiB
5Accepted3/33ms2680 KiB
6Accepted2/24ms2972 KiB
7Accepted3/34ms3176 KiB
8Accepted2/24ms3308 KiB
9Accepted3/34ms3464 KiB
10Accepted2/24ms3492 KiB
11Accepted3/34ms3448 KiB
12Accepted1/157ms7496 KiB
13Accepted2/259ms8720 KiB
14Accepted1/157ms9856 KiB
15Accepted2/257ms11084 KiB
16Accepted1/135ms11636 KiB
17Accepted2/243ms12232 KiB
18Accepted1/135ms12636 KiB
19Accepted2/229ms13016 KiB
20Accepted2/229ms13728 KiB
21Accepted3/348ms14336 KiB
22Accepted2/241ms14852 KiB
23Accepted3/346ms15332 KiB
24Accepted2/248ms16032 KiB
25Accepted3/348ms16748 KiB
26Accepted2/248ms17452 KiB
27Accepted3/361ms18428 KiB
28Accepted2/261ms19456 KiB
29Accepted3/357ms20652 KiB
30Accepted3/33ms17808 KiB
31Accepted3/33ms17916 KiB
32Accepted3/33ms17916 KiB
33Accepted3/33ms17776 KiB
34Accepted3/33ms17896 KiB