A. Bear and Elections
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard 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.

Sample test(s)
Input
5
5 1 11 2 8
Output
4
Input
4
1 8 8 8
Output
6
Input
2
7 6
Output
0

题目描述:给你n个人,第二行有n个数,每个数代表第i个人的选票数量。现在第1号人想要赢得选举。所以在选票数量上1号候选人的选票数量
必须严格大于其他候选人的选票数。如果1号候选人的选票不能让他被选举上,他就会去投其他人的。直到他的票数最多。问:他最少需要偷多少张?
(偷的选票可以来自其他的任何人) 将2--n号人的选票数加入到一个大数优先的优先队列。只要1号候选人的票数少于对首人的,就将队首元素取出队列&&值-1, 1号人的+1.计数器+1,再将这个
元素加入到优先队列中。直到1号人的票数>队首元素。 code:
#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm> using namespace std; int main()
{
int n;
while(scanf("%d", &n)!=EOF)
{
int head;
priority_queue<int, vector<int>, less<int> >q;
scanf("%d", &head);
int cur;
for(int i=2; i<=n; i++){
scanf("%d", &cur); q.push(cur);
}
int ans=0;
while(head<=q.top())
{
cur=q.top(); q.pop();
head++; cur--; ans++;
q.push(cur);
}
printf("%d\n", ans);
}
return 0;
}

												

最新文章

  1. Mac下配置Apache + Php + Mysql环境
  2. android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存
  3. 一致性 hash 算法( consistent hashing )a
  4. Java文件操作工具类(复制、删除、重命名、创建路径)
  5. 认识Runtime1
  6. Codeforces 176B (线性DP+字符串)
  7. LVM逻辑分区
  8. Scrum团队成立,阅读《构建之法》第6~7章,并参考以下链接,发布读后感、提出问题、并简要说明你对Scrum的理解
  9. 在Tomcat上运行ADF Essentials应用
  10. Table显示滚动条
  11. 扩展KMP模板
  12. 动态树(Link Cut Tree) :SPOJ 375 Query on a tree
  13. oracle权限问题
  14. 图片处理之-Bitmap.Config,jpeg压缩与大小
  15. 【转】判断URL是否能够访问
  16. 微信小程序navigator
  17. Android天坑ImageView控件上下留白原因与解决
  18. iOS开发面试题整理
  19. 通过github搭建个人博客
  20. ip netns

热门文章

  1. 猜数字游戏-python
  2. splay tree旋转操作 hdu 1890
  3. sql server 2008获取表的字段注释
  4. vs报错找不到错在哪里!Validation failed for one or more entities
  5. Storm 提交任务过程详解 (不对地方麻烦指正)
  6. css 生效顺序 less 写法
  7. Centos7安装dubbo管理控制台
  8. python的标准类型分类
  9. linux增加 路由使两个不同的网段可以访问
  10. Python基础-set集合