129092025-01-03 11:56:14PKBOsztozkodás (75 pont)cpp17Wrong answer 24/7561ms812 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    
    vector<int> ajandekok(N);
    
    // Bemenet olvasása
    for (int i = 0; i < N; ++i) {
        cin >> ajandekok[i];
    }
    
    // Az ajándékok értékének rendezése csökkenő sorrendbe
    sort(ajandekok.begin(), ajandekok.end(), greater<int>());
    
    long long anna_sum = 0, bea_sum = 0;
    
    // Ha már csak K vagy annál kevesebb ajándék marad
    if (N <= K) {
        // Ha páros számú ajándékok maradnak, Bea veszi el mindet
        if (N % 2 == 0) {
            for (int i = 0; i < N; ++i) {
                bea_sum += ajandekok[i];
            }
        }
        // Ha páratlan számú ajándékok maradnak, Anna veszi el mindet
        else {
            for (int i = 0; i < N; ++i) {
                anna_sum += ajandekok[i];
            }
        }
    } else {
        // Normál választás, amikor több mint K ajándék marad
        for (int i = 0; i < N; ++i) {
            if (i % 2 == 0) {  // Anna választ
                anna_sum += ajandekok[i];
            } else {  // Bea választ
                bea_sum += ajandekok[i];
            }
        }
    }
    
    // Kimenet
    cout << anna_sum << " " << bea_sum << endl;
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base24/75
1Accepted0/01ms504 KiB
2Accepted0/01ms320 KiB
3Accepted2/21ms508 KiB
4Wrong answer0/31ms320 KiB
5Wrong answer0/31ms320 KiB
6Wrong answer0/22ms320 KiB
7Wrong answer0/32ms320 KiB
8Wrong answer0/23ms320 KiB
9Wrong answer0/32ms508 KiB
10Wrong answer0/22ms500 KiB
11Wrong answer0/32ms320 KiB
12Wrong answer0/157ms808 KiB
13Wrong answer0/257ms804 KiB
14Wrong answer0/157ms804 KiB
15Wrong answer0/257ms568 KiB
16Accepted1/132ms572 KiB
17Accepted2/241ms804 KiB
18Accepted1/132ms568 KiB
19Accepted2/227ms808 KiB
20Accepted2/228ms804 KiB
21Accepted3/346ms804 KiB
22Accepted2/239ms808 KiB
23Wrong answer0/343ms808 KiB
24Wrong answer0/246ms568 KiB
25Wrong answer0/348ms800 KiB
26Wrong answer0/246ms804 KiB
27Accepted3/361ms808 KiB
28Wrong answer0/261ms568 KiB
29Wrong answer0/357ms812 KiB
30Accepted3/31ms320 KiB
31Accepted3/31ms320 KiB
32Wrong answer0/31ms320 KiB
33Wrong answer0/31ms320 KiB
34Wrong answer0/31ms320 KiB