181812025-10-10 13:07:09dfehervariOsztozkodás (75 pont)cpp17Wrong answer 33/7561ms812 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<int> 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<int> 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){
    int 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
base33/75
1Accepted0/01ms508 KiB
2Accepted0/01ms316 KiB
3Accepted2/21ms316 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Wrong answer0/22ms316 KiB
7Wrong answer0/33ms412 KiB
8Wrong answer0/23ms416 KiB
9Wrong answer0/32ms316 KiB
10Wrong answer0/23ms408 KiB
11Wrong answer0/33ms316 KiB
12Wrong answer0/157ms800 KiB
13Wrong answer0/257ms756 KiB
14Wrong answer0/157ms800 KiB
15Wrong answer0/257ms564 KiB
16Accepted1/132ms564 KiB
17Accepted2/241ms564 KiB
18Accepted1/132ms796 KiB
19Accepted2/228ms564 KiB
20Accepted2/228ms568 KiB
21Wrong answer0/346ms564 KiB
22Accepted2/239ms564 KiB
23Wrong answer0/343ms568 KiB
24Wrong answer0/246ms812 KiB
25Wrong answer0/346ms564 KiB
26Wrong answer0/246ms564 KiB
27Wrong answer0/361ms564 KiB
28Wrong answer0/261ms564 KiB
29Wrong answer0/357ms796 KiB
30Accepted3/31ms500 KiB
31Accepted3/31ms316 KiB
32Accepted3/31ms316 KiB
33Accepted3/31ms316 KiB
34Accepted3/31ms316 KiB