Advertisement
Josif_tepe

Untitled

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