Source Code
#include <fstream>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <array>
#include <set>
using namespace std;
int main()
{
    /*int _;
    cin>>_;
    while (_--)
    {
    }*/
    long long n,k,ans=0;
    cin>>n>>k;
    vector <long long> ary;
    for(int i=0; i<n ;i++)
    {
        int x;
        cin>>x;
        ary.push_back(x);
    }
    sort(ary.begin(),ary.end(),greater<long long>());

    int x=1;
    for(int i = 1; i<n; i++)
    {
        if(x==k)
        {
            x=1;
            continue;
        }
        x++;
        ans+=ary[i];
    }

    cout<<ans<<endl;
}
Copy
Offer Abbro
GNU G++17
2 ms
184 KB
Wrong Answer