181832025-10-10 15:15:33dfehervariOsztozkodás (75 pont)cpp17Time limit exceeded 70/75600ms1340 KiB
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

int main(){
    //std::cout<<"Osztozkodás\n";
    int N,k;
    std::cin>>N>>k; //N, k beolvasása
    std::vector<long long> ajandekok(N); //vektor feltöltése
    for(int i=0;i<N;++i){
        std::cin>>ajandekok[i];
    }
    sort(ajandekok.begin(),ajandekok.end(), [](int a, int b) {return a > b;}); //vektor növekvő sorba rendezése
    

    /*bemenet kiíratása
    for(int i=0;i<N;++i){
        std::cout<<ajandekok[i]<<" ";
    }
    std::cout<<"\n";
    */
   
   std::vector<long long> AB = {0,0};
   int ab = 0;
   int i=0;
   while(i<N-k){
    AB[ab] += ajandekok[i];
    ab = 1-ab;
    ++i;
   }
   //std::cout<<AB[0]<<" "<<AB[1];
   
   while(i<N){
    long long osszeg=0;
    for(int j=i;j<N;++j){
       osszeg+=ajandekok[j];
   }
    if (ajandekok[i]>osszeg){
       AB[ab]+=ajandekok[i];
       ab = 1-ab;
       ++i;
    }
    else{
        AB[ab]+=osszeg;
        break;

    }

   }
   std::cout<<AB[0]<<" "<<AB[1];

   return 0;
}
SubtaskSumTestVerdictTimeMemory
base70/75
1Accepted0/01ms512 KiB
2Accepted0/01ms512 KiB
3Accepted2/21ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted2/22ms316 KiB
7Accepted3/33ms316 KiB
8Accepted2/22ms316 KiB
9Accepted3/32ms396 KiB
10Accepted2/22ms316 KiB
11Accepted3/32ms316 KiB
12Accepted1/154ms1192 KiB
13Accepted2/254ms1188 KiB
14Accepted1/154ms1192 KiB
15Accepted2/254ms1192 KiB
16Accepted1/132ms1076 KiB
17Accepted2/239ms1200 KiB
18Accepted1/132ms1076 KiB
19Accepted2/227ms1076 KiB
20Accepted2/227ms1340 KiB
21Accepted3/346ms1076 KiB
22Accepted2/237ms1164 KiB
23Accepted3/341ms1120 KiB
24Accepted2/246ms1192 KiB
25Accepted3/346ms1268 KiB
26Accepted2/246ms1076 KiB
27Time limit exceeded0/3600ms1076 KiB
28Time limit exceeded0/2577ms1076 KiB
29Accepted3/354ms1192 KiB
30Accepted3/31ms316 KiB
31Accepted3/31ms316 KiB
32Accepted3/31ms316 KiB
33Accepted3/31ms316 KiB
34Accepted3/31ms316 KiB