一个人想要自己是最多的个数,开个优先队列,然后从第一个开始减一,直到自己是最大就好了
#include<bits/stdc++.h>
//#include<iostream>
//#include<queue>
//using namespace std;
#define sf scanf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf printf
#define prf(x) printf("%d
",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+100;
const double eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
const int N=1e5+7;
priority_queue<int>v;
int main()
{
int num,n,x;scf(n);
n--;
scf(num);
if(n==0)
{
pf("0
");
return 0;
}
while(n--)
{
scf(x);
v.push(x);
}
int ans=0;
while(1)
{
if(num>=v.top()) break;
x=v.top();
v.pop();
x--;v.push(x);
num++;
ans++;
}
prf(ans);
return 0;
}