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;
}

												

codeforces Codeforces Round #318 div2 A. Bear and Elections 【优先队列】的更多相关文章

  1. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections 优先队列

                                                    A. Bear and Elections                               ...

  2. Codeforces Beta Round #94 div2 D 优先队列

    B. String time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  3. Codeforces Beta Round #107(Div2)

    B.Phone Numbers 思路:就是简单的结构体排序,只是这里有一个技巧,就是结构体存储的时候,直接存各种类型的电话的数量是多少就行,在读入电话的时候,既然号码是一定的,那么就直接按照格式%c读 ...

  4. Codeforces Beta Round #73(Div2)

    A - Chord 题意:就是环中有12个字符,给你三个字符,判断他们之间的间隔,如果第一个和第二个间隔是3并且第二个和第三个间隔是4,那么就输出minor,如果第一个和第二个间隔是4并且第二个和第三 ...

  5. Codeforces Beta Round #3 D. Least Cost Bracket Sequence 优先队列

    D. Least Cost Bracket Sequence 题目连接: http://www.codeforces.com/contest/3/problem/D Description This ...

  6. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  7. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  8. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  9. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

随机推荐

  1. C++ 矩阵计算库 :Eigen库

    Eigen http://eigen.tuxfamily.org/index.php?title=Main_Page 下载http://bitbucket.org/eigen/eigen/get/3. ...

  2. [Unity热更新]tolua# & LuaFramework(一):基础

    一.tolua# c#调用lua:LuaState[变量名/函数名] 1.LuaState a.执行lua代码段 DoString(string) DoFile(.lua文件名) Require(.l ...

  3. The Best Hacking Tools

    The Best Hacking Tools Hacking Tools : List of security tools specifically aimed toward security pro ...

  4. 【BZOJ2199】[Usaco2011 Jan]奶牛议会 2-SAT

    [BZOJ2199][Usaco2011 Jan]奶牛议会 Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要 ...

  5. 爬虫实战【6】Ajax内容解析-今日头条图集

    Ajax技术 AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). Ajax并不是新的编程语言,而是一种使用现有标准的新方法,当然 ...

  6. 三、docker官网注册docker id

    docker官网注册docker ID 电脑注册docker没有成功,网上有人说用手机注册,试了一下确实可以注册. 1.下载蓝灯软件开启FQ代理. 2.登录网站,按照提示注册.

  7. ASP-Command-SQL格式

    conn.open constrSet c=Server.CreateObject("ADODB.Command")With cSet .ActiveConnection = co ...

  8. PowerPC架构与X86架构

    PowerPC架构 PowerPC是一种精简指令集(RISC)架构的中央处理器(CPU),其基本的设计源自IBM(国际商用机器公司)的POWER(Performance Optimized With ...

  9. [note]克鲁斯卡尔重构树

    克鲁斯卡尔重构树 又叫并查集重构树 大概在NOI2018之前还是黑科技 现在?烂大街了 主要是针对图上的对边有限制的一类问题 比如每次询问一个点u不能经过边权大于w的边能走到的第k大点权是多少 也就是 ...

  10. Jquery添加元素append及阻止表单提交submit

    HTML代码: <td><input name="duration[]" value="" type="text" /&g ...