CF574A.Bear and Elections

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.

There are nn candidates, including Limak. We know how many citizens are going to vote for each candidate. Now ii -th candidate would get aia_{i} votes. Limak is candidate number 11 . 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?

输入格式

The first line contains single integer nn ( 2<=n<=1002<=n<=100 ) - number of candidates.

The second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=10001<=a_{i}<=1000 ) - number of votes for each candidate. Limak is candidate number 11 .

Note that after bribing number of votes for some candidate might be zero or might be greater than 10001000 .

输出格式

Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.

输入输出样例

  • 输入#1

    5
    5 1 11 2 8
    

    输出#1

    4
    
  • 输入#2

    4
    1 8 8 8
    

    输出#2

    6
    
  • 输入#3

    2
    7 6
    

    输出#3

    0
    

说明/提示

In the first sample Limak has 55 votes. One of the ways to achieve victory is to bribe 44 citizens who want to vote for the third candidate. Then numbers of votes would be 9,1,7,2,89,1,7,2,8 (Limak would have 99 votes). Alternatively, Limak could steal only 33 votes from the third candidate and 11 vote from the second candidate to get situation 9,0,8,2,89,0,8,2,8 .

In the second sample Limak will steal 22 votes from each candidate. Situation will be 7,6,6,67,6,6,6 .

In the third sample Limak is a winner without bribing any citizen.

首页