Advertisement
Josif_tepe

Untitled

Jun 1st, 2024
695
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. int main()
  6. {
  7.     int n;
  8.     cin >> n;
  9.  
  10.     int niza[n];
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> niza[i];
  13.     }
  14.     sort(niza, niza + n);
  15.  
  16.     int S = 0, E = n - 1;
  17.     int res = 0;
  18.     while(S < E) {
  19.         while(niza[S] > 0 and S < E) {
  20.             E--;
  21.             niza[S]--;
  22.             res++;
  23.         }
  24.         S++;
  25.     }
  26.     cout << res << endl;
  27.     return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement