125382024-12-21 16:02:41PappMatyasOsztozkodás (75 pont)cpp17Wrong answer 18/7559ms808 KiB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


// 10 5
int main()
{
    int n, k, a = 0, b = 0, as, bs, am, bm;
    int ab = 0;
    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];
        }
    }
    am = as;
    bm = bs;
    int sum = as + bs - a - b;
    for(int i = k - 1; i >= 0; i--)
    {
        if(i % 2 != n % 2)
        {
            if(sum + a > am && (ab == 1 || ab == 0))
            {
                am = sum + a;
                bm = b;
                ab = 1;
            }
            a+=S[i];
        }
        else
        {
            if(sum + b > bm && (ab == 2 || ab == 0))
            {
                bm = sum + b;
                am = a;
                ab = 2;
            }
            b+=S[i];
        }
        sum-=S[i];
    }
    cout << am << " " << bm;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/75
1Accepted0/01ms320 KiB
2Accepted0/01ms320 KiB
3Accepted2/21ms320 KiB
4Accepted3/31ms320 KiB
5Accepted3/31ms320 KiB
6Wrong answer0/22ms320 KiB
7Wrong answer0/32ms508 KiB
8Wrong answer0/22ms320 KiB
9Wrong answer0/32ms508 KiB
10Wrong answer0/22ms500 KiB
11Wrong answer0/32ms416 KiB
12Wrong answer0/154ms708 KiB
13Wrong answer0/254ms808 KiB
14Wrong answer0/154ms568 KiB
15Wrong answer0/254ms804 KiB
16Accepted1/130ms756 KiB
17Accepted2/239ms788 KiB
18Accepted1/130ms568 KiB
19Accepted2/225ms568 KiB
20Accepted2/225ms568 KiB
21Wrong answer0/345ms568 KiB
22Accepted2/237ms804 KiB
23Wrong answer0/341ms568 KiB
24Wrong answer0/245ms568 KiB
25Wrong answer0/345ms804 KiB
26Wrong answer0/245ms568 KiB
27Wrong answer0/359ms568 KiB
28Wrong answer0/257ms568 KiB
29Wrong answer0/354ms800 KiB
30Wrong answer0/31ms320 KiB
31Wrong answer0/31ms508 KiB
32Wrong answer0/31ms320 KiB
33Wrong answer0/31ms320 KiB
34Wrong answer0/31ms320 KiB