Advertisement
Josif_tepe

Untitled

Mar 24th, 2024
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     cin >> n;
  8.    
  9.     int niza[n];
  10.     for(int i = 0; i < n; i++) {
  11.         cin >> niza[i];
  12.     }
  13.     sort(niza, niza + n);
  14.     int S = 0;
  15.     int E = n - 1;
  16.     int res = 0;
  17.     while(S < E) {
  18.         while(niza[S] > 0 and S < E) {
  19.             E--;
  20.             niza[S]--;
  21.             res++;
  22.         }
  23.         S++;
  24.     }
  25.     cout << res << endl;
  26.     return 0;
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement