Source Code
#include <iostream>

using std::swap;
using std::cout;
using std::cin;
using std::endl;


int main()
{


    int n, k;
    cin >> n >> k;
    int a[int(n*1.5)];

    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int smallest;
    for(int i=0; i<n-1; i++){
        smallest = i;
        for (int u=i+1; u<n; u++){
            if (a[smallest] > a[u]){
                smallest = u;
            }
        }
        swap(a[smallest], a[i]);
    }

    int sums = 0;
    for(int i=0; i<(k); i++){
        for(int u=i; u<n; u+=k){
            if(a[i] != 0) break;
            else if(a[u]+1 != a[u+k]) {sums += a[u]+1; break;}
        }
    }

    cout << sums;

    return 0;
}
Copy
Bitar The Handy Man Abd20200355
GNU G++17
2068 ms
1.1 MB
Time Limit Exceeded