Advertisement
Josif_tepe

Untitled

Apr 5th, 2024
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  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.    
  16.     sort(niza, niza + n);
  17.    
  18.     int i = 0, j = n - 1, res = 0;
  19.     while(i < j) {
  20.         while(i < j and niza[i] > 0) {
  21.             niza[i]--;
  22.             j--;
  23.             res++;
  24.         }
  25.         i++;
  26.     }
  27.     cout << res << endl;
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement