Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- bool compar(int a, int b){
- return a > b;
- }
- int main(){
- int n, a[200], i, cnt = 0, j;
- cin >> n;
- for (i = 0; i < n; i++)
- cin >> a[i];
- sort(a + 1, a + n, compar);
- while (a[0] <= a[1]){
- a[0]++;
- a[1]--;
- j = 1;
- cnt++;
- while (j < n - 1 && a[j] < a[j + 1]){
- swap(a[j], a[j + 1]);
- j++;
- }
- }
- cout << cnt << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement