Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)A
2016-05-28 20:01
417 查看
思路:水题
#include<bits\stdc++.h>
using namespace std;
int a[105];
int main()
{
int n;
scanf("%d",&n);
for(int i = 0;i<n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n);
int ans = 0;
int s = a[0];
while(s <= a[n-1])
{
ans++;
s++;
a[n-1]--;
sort(a+1,a+n);
}
printf("%d\n",ans);
}
A. Bear and Elections
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 ai 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?
Input
The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 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.
Output
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
Examples
input
5
5 1 11 2 8
output
4
input
4
1 8 8 8
output
6
input
2
7 6
output
0
Note
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.
#include<bits\stdc++.h>
using namespace std;
int a[105];
int main()
{
int n;
scanf("%d",&n);
for(int i = 0;i<n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n);
int ans = 0;
int s = a[0];
while(s <= a[n-1])
{
ans++;
s++;
a[n-1]--;
sort(a+1,a+n);
}
printf("%d\n",ans);
}
A. Bear and Elections
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 ai 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?
Input
The first line contains single integer n (2 ≤ n ≤ 100) - number of candidates.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 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.
Output
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
Examples
input
5
5 1 11 2 8
output
4
input
4
1 8 8 8
output
6
input
2
7 6
output
0
Note
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.
相关文章推荐
- C++值赋值运算符重载
- 【转】plist文件的内容清空
- Firebug
- [小技巧]如果一键通过正则kill掉进程
- Bootstrap 插件【四】
- C#客户端发送http请求与服务器通信
- 练习三 Problem B
- zhenai
- 手撸编译器(1)...
- 打印菜单界面,用c语言实现二叉树的基本操作
- shell脚本---grep、awk、sed工具
- 将博客搬至CSDN
- ListView Item点击一直变色
- port from solaris to linux for c
- Tomcat 通过listener 启动netty 服务
- 练习三 Problem O
- 【HDU】 1370 Biorhythms
- [Linux]使用PHP编写Gearman的Worker守护进程
- 大组合数取模之lucas定理模板,1<=n<=m<=1e9,1<p<=1e6,p必须为素数 复制代码
- iOS指南针