Cod sursa(job #2767854)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 8 august 2021 11:44:37
Problema Grupuri Scor 26
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("grupuri.in");
ofstream fout("grupuri.out");

const int nmax = 100005;
int n, k, a[nmax];

int main(){
    fin >> k >> n;
    for (int i = 1; i <= n; ++i){
        fin >> a[i];
    }
    bool ok = true;
    int cnt = 0;
    while (ok){
        for (int i = n; i >= n - k + 1; --i){
            if (a[i] == 0){
                ok = false;
                break;
            }
        }
        if (!ok){
            break;
        }
        for (int i = n; i >= n - k + 1; --i){
            a[i]--;
        }
        ++cnt;
        sort(a + 1, a + n + 1);
    }
    fout << cnt;
    return 0;
}