CF574A.Bear and Elections
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
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 n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get a__i 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 是一只渴望权力与崇拜的北极熊。他希望在即将到来的选举中获胜,从而统治熊国(Bearland)。
共有 n 位候选人,其中包括 Limak。我们已知每位候选人将获得的选票数:第 i 位候选人将获得 ai 票。Limak 是 1 号候选人。为了赢得选举,他必须获得严格多于其他任何一位候选人的票数。
胜利比一切更重要,因此 Limak 决定舞弊。他将通过贿赂部分选民,从对手那里窃取选票。贿赂一名选民需要赠送其一颗糖果——因为选民都是熊,而熊喜欢糖果。Limak 手中的糖果数量有限,他想知道:他至少需要贿赂多少名选民?
输入格式
The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates.
The second line contains n space-separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate might be zero or might be greater than 1000.
第一行包含一个整数 n(2≤n≤100),表示候选人的数量。
第二行包含 n 个以空格分隔的整数 a1,a2,…,an(1≤ai≤1000),表示每位候选人获得的票数。Limak 是编号为 1 的候选人。
注意:贿赂之后,某位候选人的票数可能为 0,也可能超过 1000。
输出格式
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
输出Limak为确保其得票数严格多于其他任何候选人而必须贿赂的最少市民人数。
输入输出样例
输入#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 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate to get situation 9, 0, 8, 2, 8.
In the second sample Limak will steal 2 votes from each candidate. Situation will be 7, 6, 6, 6.
In the third sample Limak is a winner without bribing any citizen.
在第一个样例中,Limak 有 5 票。一种获胜的方式是贿赂 4 位打算投给第三位候选人的市民。此时各候选人的得票数将变为 9,1,7,2,8(Limak 将获得 9 票)。另一种方式是,Limak 仅从第三位候选人处窃取 3 票,并从第二位候选人处窃取 1 票,从而得到得票数分布 9,0,8,2,8。
在第二个样例中,Limak 将从每位候选人处窃取 2 票。最终得票数分布为 7,6,6,6。
在第三个样例中,Limak 无需贿赂任何市民即已获胜。
输入解题思路,AI测评打分。不知道怎么写?