125392024-12-21 16:04:35PappMatyasOsztozkodás (75 pont)cpp17Wrong answer 36/7561ms808 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n, k;
    long long a = 0, b = 0, as, bs;
    vector<int> S;
    cin >> n >> k;
    S.resize(n);
    for(int i = 0; i < n; i++)
    {
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    if(n == 2)
    {
        cout << S[1] << " " << S[0];
    }
    for(int i = n - 1; i >= k; i--)
    {
        if(i % 2 != n % 2)
        {
            a+=S[i];
        }
        else
        {
            b+=S[i];
        }
    }
    as = a;
    bs = b;
    for(int i = k - 1; i >= 0; i--)
    {
        if(i % 2 != n % 2)
        {
            as+=S[i];
        }
        else
        {
            bs+=S[i];
        }
    }
    int sum = as + bs - a - b;
    for(int i = k - 1; i >= 0; i--)
    {
        if(i % 2 != n % 2)
        {
            if(sum + a > as)
            {
                a = sum + a;
                break;
            }
            a+=S[i];
        }
        else
        {
            if(sum + b > bs)
            {
                b = sum + b;
                break;
            }
            b+=S[i];
        }
        sum-=S[i];
    }
    cout << a << " " << b;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base36/75
1Accepted0/01ms320 KiB
2Accepted0/01ms500 KiB
3Accepted2/21ms320 KiB
4Accepted3/31ms320 KiB
5Accepted3/31ms320 KiB
6Accepted2/22ms320 KiB
7Accepted3/32ms320 KiB
8Wrong answer0/22ms320 KiB
9Wrong answer0/33ms320 KiB
10Wrong answer0/22ms416 KiB
11Wrong answer0/32ms320 KiB
12Wrong answer0/157ms808 KiB
13Wrong answer0/257ms572 KiB
14Wrong answer0/157ms804 KiB
15Wrong answer0/257ms568 KiB
16Accepted1/134ms568 KiB
17Accepted2/241ms568 KiB
18Accepted1/132ms568 KiB
19Accepted2/228ms568 KiB
20Accepted2/228ms568 KiB
21Accepted3/346ms568 KiB
22Accepted2/239ms568 KiB
23Accepted3/343ms568 KiB
24Accepted2/246ms568 KiB
25Accepted3/346ms568 KiB
26Accepted2/248ms800 KiB
27Wrong answer0/361ms568 KiB
28Wrong answer0/261ms572 KiB
29Wrong answer0/357ms808 KiB
30Wrong answer0/31ms320 KiB
31Wrong answer0/31ms320 KiB
32Wrong answer0/31ms320 KiB
33Wrong answer0/31ms320 KiB
34Wrong answer0/31ms320 KiB