181842025-10-10 15:21:33dfehervariOsztozkodás (75 pont)cpp17Accepted 75/7561ms1272 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];
   long long osszeg=0;
   for(int j=i;j<N;++j){
       osszeg+=ajandekok[j];
       }
   while(i<N){
    
    
   
    if (ajandekok[i]>osszeg){
       AB[ab]+=ajandekok[i];
       ab = 1-ab;
       osszeg -=ajandekok[i];
       ++i;
       
    }
    else{
        AB[ab]+=osszeg;
        break;

    }

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

   return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms500 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted2/22ms316 KiB
7Accepted3/33ms316 KiB
8Accepted2/22ms344 KiB
9Accepted3/33ms424 KiB
10Accepted2/23ms316 KiB
11Accepted3/33ms316 KiB
12Accepted1/157ms1076 KiB
13Accepted2/257ms1188 KiB
14Accepted1/157ms1192 KiB
15Accepted2/257ms1268 KiB
16Accepted1/132ms1080 KiB
17Accepted2/243ms1076 KiB
18Accepted1/132ms1076 KiB
19Accepted2/227ms1200 KiB
20Accepted2/227ms1272 KiB
21Accepted3/346ms1188 KiB
22Accepted2/239ms1076 KiB
23Accepted3/343ms1188 KiB
24Accepted2/250ms1192 KiB
25Accepted3/346ms1268 KiB
26Accepted2/246ms1188 KiB
27Accepted3/361ms1076 KiB
28Accepted2/261ms1076 KiB
29Accepted3/357ms1076 KiB
30Accepted3/31ms352 KiB
31Accepted3/31ms316 KiB
32Accepted3/31ms316 KiB
33Accepted3/31ms316 KiB
34Accepted3/31ms316 KiB