Advertisement
IlidanBabyRage

a.cpp

Aug 29th, 2015
65
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 <cstdio>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. bool compar(int a, int b){
  9.     return a > b;
  10. }
  11.  
  12. int main(){
  13.    
  14.     int n, a[200], i, cnt = 0, j;
  15.     cin >> n;
  16.     for (i = 0; i < n; i++)
  17.         cin >> a[i];
  18.     sort(a + 1, a + n, compar);
  19.     while (a[0] <= a[1]){
  20.         a[0]++;
  21.         a[1]--;
  22.         j = 1;
  23.         cnt++;
  24.         while (j < n - 1 && a[j] < a[j + 1]){
  25.             swap(a[j], a[j + 1]);
  26.             j++;
  27.         }
  28.     }
  29.     cout << cnt << endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement