Josif_tepe

Untitled

Jan 21st, 2026
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.    
  10.     vector<int> v(n);
  11.     for(int i = 0; i < n; i++) {
  12.         cin >> v[i];
  13.     }
  14.    
  15.     sort(v.begin(), v.end());
  16.    
  17.     int S = 0, E = n - 1;
  18.     int res = 0;
  19.    
  20.     while(S < E) {
  21.         while(v[S] > 0 and S < E) {
  22.             E--;
  23.             v[S]--;
  24.             res++;
  25.         }
  26.         S++;
  27.     }
  28.    
  29.     cout << res << endl;
  30.    
  31. }
  32.  // 3 4 5 7 9
  33.  
  34.  
  35.  
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment