题干:

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.

题目大意:

n个人参加选举,现在知道目前n个人各自的得票数,现在要让1号人获胜(也就是1号的得票数严格大于其他人的得票数),问最少要贿赂几个人?

解题报告:

直接优先队列可以搞出来。

AC代码:


#include<bits/stdc++.h>using namespace std;
priority_queue<int> pq;
int main()
{int n,ans=0,my,tmp;scanf("%d%d",&n,&my);//ans相当于a[1]for(int i = 2; i<=n; i++){scanf("%d",&tmp);if(tmp >= my) pq.push(tmp);}if(pq.empty()) {puts("0");return 0;}while(my<=pq.top()){my++;ans++;tmp = pq.top();pq.pop();pq.push(tmp-1);}printf("%d\n",ans);return 0;
}

wa代码:

#include<bits/stdc++.h>using namespace std;
const int MAX = 1e5 +5;
int a[MAX];
int main()
{int n,my,top=0,tmp;cin>>n;scanf("%d",&my);for(int i = 2; i<=n; i++) {scanf("%d",&tmp);if(tmp >= my) a[++top] = tmp;}if(top == 0) {puts("0");return 0;}int sum = my;for(int i = 1; i<=top; i++) {sum += a[i];}double ans = ceil(sum*1.0/(top+1));if(sum%(top+1) == 0) {printf("%d\n",(int)ans-my + 1);}else printf("%d\n",(int)ans-my);return 0 ;} 

总结:

刚开始想错了,想直接找到平均值然后看是否需要加1就可以了。但是这样是不对的,因为比如1,897,2这三个数,平均值是300,但是你答案不能直接在300附近找,因为这样看的话相当于897也分给了2一部分,才能平均成300,但是依据题意,只有1号选手可以贿赂其他人,而对于其他人,得票数只能减少不能增加的!(也就是,其他人都不能贿赂别人)。所以这种策略(直接算平均值)是失效的,对于这个题。

emmm想一下,这题也可以二分答案去做吗?

*【CodeForces - 574A】Bear and Elections (优先队列,水题模拟)相关推荐

  1. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  2. 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)

    题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...

  3. 【HDU - 1870】愚人节的礼物(水题模拟 思想类似于栈?)

    题干: 四月一日快到了,Vayko想了个愚人的好办法--送礼物.嘿嘿,不要想的太好,这礼物可没那么简单,Vayko为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物.盒子里面可以再放零个或者多个盒子 ...

  4. VK Cup 2016 - Round 1 (Div. 2 Edition) A. Bear and Reverse Radewoosh 水题

    A. Bear and Reverse Radewoosh 题目连接: http://www.codeforces.com/contest/658/problem/A Description Lima ...

  5. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) A. Bear and Three Balls 水题

    A. Bear and Three Balls 题目连接: http://www.codeforces.com/contest/653/problem/A Description Limak is a ...

  6. Codeforces Round #300 A. Cutting Banner 水题

    A. Cutting Banner Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...

  7. CodeForces - 1263A Sweet Problem(思维,水题)

    题目链接:点击查看 题目大意:给出三种颜色的糖果,分别表示为r,g,b,现在Tanya每天可以吃两个不同颜色的糖果,问最多可以吃多少天 题目分析:大水题一个,但自己真的蠢,一开始思路混乱,写了一大堆乱 ...

  8. C - Internet Address CodeForces - 245B(有些思维的水题)

    Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote ...

  9. 【CodeForces - 1197C】Array Splitting(水题)

    题干: You are given a sorted array a1,a2,-,ana1,a2,-,an (for each index i>1i>1 condition ai≥ai−1 ...

最新文章

  1. 语言相关系数显著性_相关性分析在SPSS中的具体操作,一文读懂相关系数的含义及使用——【杏花开生物医药统计】...
  2. 如何关闭win10自动更新_如何关闭win10系统自动更新
  3. 热泵精馏_精馏干货16 || 分子蒸馏
  4. Mybatis 动态Sql语句《常用》
  5. 学习ASP.NET Core Razor 编程系列十八——并发解决方案
  6. rust种的南瓜为什么老是消失_冷天早餐别将就,用南瓜和萝卜这样做,鲜香松软,营养好吃又管饱...
  7. The X protocol C-language Binding (XCB) is a replacement for Xlib
  8. 真强啊!建议每一个打算学Java的人都来看看!
  9. 微信小程序云开发教程-微信小程序的JS高级-页面间数据传递
  10. java batik_java – Batik传递库依赖项
  11. 人人商城小程序getUserProfile登录接口升级
  12. 计算科学导论读书笔记
  13. word文档中实现目录索引中标题加粗,前导符和页码不加粗
  14. PPT母版制作及自定义主题
  15. 钢铁骑士团服务器端文件,《钢铁骑士团》新手必读 游戏道具介绍
  16. Excel中ISEVEN函数用法之判断数值奇偶性
  17. Windows/Linux混合刻录之后,光盘文件不见了?
  18. 服务器如何查看隐藏文件,BlueHost主机如何查看隐藏文件夹
  19. 关于Vivado综合选项——Out of context per IP和Gobal
  20. 医疗IT系统在手术部供配电间的应用

热门文章

  1. 力扣:组合总和 II DFS剪枝
  2. java+向前进一_Java 线程基础
  3. mysql 端口time_wait_linux上大量tcp端口处于TIME_WAIT的问题
  4. 1245C. Constanze‘s Machine
  5. linux php oauth安装,php – 无法在Linux上安装OAuth
  6. ff14拆区后哪个服务器人最多,FF14拆区可以转服吗 拆区期间转服教程
  7. h5 storage事件监听
  8. 以python程序调用的系统_python 系统调用的实例详解
  9. 为Cubieboard打造完美Debian系统
  10. linux c 内存elf,gcc加入linux ELF有什么功能?