Untitled

mail@pastecode.io avatar
unknown
c_cpp
22 days ago
499 B
1
Indexable
Never
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    
    int niza[n];
    for(int i = 0; i < n; i++) {
        cin >> niza[i];
    }
    sort(niza, niza + n);
    
    int S = 0, E = n - 1;
    int res = 0;
    while(S < E) {
        while(S < E and niza[S] > 0) {
            niza[S]--;
            E--;
            res++;
        }
        S++;
    }
    cout << res << endl;
   return 0;
}
Leave a Comment