Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would getai votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate.
Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe?
题目就是说有个选举 ,limak一定要赢,于是乎要去别人那里偷选票,一张票票一颗糖
于是乎只要对数列里找到比limak票的多 票最多的那位,让那位的票数减1 窝们的主角limak票数加一,更新下答案。 蓝后看一下是不是所有人的票数都小于limak。有的话继续操作就好了
然而, 我代码写搓了 ,多了些没必要的东西
#include
#include
#include
using namespace std;
int s[110];
int n;
bool cmp(int a, int b)
{
return a > b;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
int s1;
scanf("%d",&s1);
for(int i = 1; i < n; i++)
{
scanf("%d",&s[i]);
s[i]-=s1;
}
sort(s+1,s+n,cmp);
int flag = 0;
int ans = 0;
while(!flag)
{
flag = 1;
for(int i = 1; i < n; i++)
{
if(s[i] >= 0){
flag = 0;
break;
}
}
if(!flag){
int t = 1;
for(int i = 1; i < n; i++)
if(s[i] > s[t])
t = i;
s[t] -= 1;
for(int i = 1; i < n; i++)
s[i] -=1;
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}