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[n];

    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 numberOfcols = (n/k)+(n%k);
    int multiArr[k][numberOfcols];

    int w = 0;
    for(int u=0; u<numberOfcols; u++){
        for (int i=0; i<k; i++){
            multiArr[i][u] = a[w];
            w++;
        }
    }

    int sums = 0;

    for (int i=0; i<k; i++){
        for(int u=0; u<numberOfcols; u++){
            if(multiArr[i][u] == -1 || multiArr[i][0] != 0) { break; }
            if(u+1 != multiArr[i][u+1])
                {
                sums+=multiArr[i][u]+1;
                break;
                }
        }
    }

    cout << sums << endl;


    return 0;
}
Copy
Bitar The Handy Man Abd20200355
GNU G++17
12 ms
1.6 MB
Wrong Answer