Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- #include <set>
- #include <map>
- #include <sstream>
- #include <cstdio>
- #include <algorithm>
- #include <stack>
- #include <queue>
- #include <cmath>
- #include <iomanip>
- //#include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll INF = (1 << 30);
- const ll inf = (1LL << 60LL);
- const ll maxn = 3e5 + 5;
- int main()
- {
- vector<int>vect;
- int n;
- cin>>n;
- int a[n + 50];
- for(int i=0;i<n;i++)
- {
- cin>>a[i];
- }
- int p=a[0];
- for(int i=1;i<n;i++)
- {
- if(a[i]>=p)
- {
- vect.push_back(a[i]);
- }
- }
- int k=0;
- if((int)vect.size() > 0){
- sort(vect.begin(),vect.end());
- int maks=vect[((int)vect.size()-1)];
- int j=(int)vect.size()-1;
- //cout<<"tuka"<<p<<endl;
- while(maks>=p)
- {
- vect[j]=vect[j]-1;
- ++p;
- sort(vect.begin(),vect.end());
- ++k;
- maks=vect[((int)vect.size()-1)];
- }
- }
- cout<<k<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement