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.1)];

    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    int smallest;
    bool Flag = false;

    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;
                Flag = true;
            }
        }
        if(Flag == false) break;
        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[u]==a[u+k]) continue;
            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
13 ms
1.2 MB
Wrong Answer