Advertisement
Josif_tepe

Untitled

Mar 30th, 2024
675
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 <cmath>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.     int niza[n];
  10.    
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> niza[i];
  13.     }
  14.     sort(niza, niza + n);
  15.     int S = 0, 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