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

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 getai 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

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<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
int main()
{
	priority_queue<int>qq;
	int a[200];
	int i,j,cnt,n,num;
	cin>>n;
	cin>>a[1];
	for(i=2;i<=n;i++) {
		cin>>num;
		if(num>=a[1]) qq.push(num);
	}
	cnt=0;
	while(!qq.empty()) {
		int t=qq.top();
		qq.pop();
		if(t>=a[1]) {
			a[1]++;
			cnt++;
			t--;
		}
		if(t>=a[1]) qq.push(t);
	}
	printf("%d\n",cnt);
	return 0;
 } 

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-05 18:37:58

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A. Bear and Elections(优先队列)的相关文章

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)

以后每做完一场CF,解题报告都写在一起吧 暴力||二分 A - Bear and Elections 题意:有n个候选人,第一个候选人可以贿赂其他人拿到他们的票,问最少要贿赂多少张票第一个人才能赢 分析:正解竟然是暴力!没敢写暴力,卡了很久,导致这场比赛差点爆零!二分的话可以优化,但对于这题来说好像不需要... 收获:以后CF div2的A题果断暴力 代码(暴力): /************************************************ * Author :Runni

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——A二分——Bear and Elections

/*贪心WA一发..二分枚举加的数赛后发现直接暴力枚举1到1000也是可以的*//************************************************ * Author :Powatr * Created Time :2015-8-30 0:58:45 * File Name :A.cpp ************************************************/ #include <cstdio> #include <algorith

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker(gcd模拟)

Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——B纯暴力——Bear and Three Musketeers

/* 写搜索WA了..赛后发现直接暴力不会超啊,,, */ /************************************************ * Author :Powatr * Created Time :2015-8-30 14:55:10 * File Name :B.cpp ************************************************/ #include <cstdio> #include <algorithm> #in

Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)

Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against

在青岛穷游打的cf codeforces Round #318 (Div. 2) A.Bear and Elections

这场cf是暑假集训后在青岛旅游打的一场,好累..... 题意:给出一个序列,要使a[1]大于a[2]~a[n],a[1]每次可以增加一,这个一从a[2]到a[[n]里面任意一个数减一扣除,求最少的步数 思路:要不断地修改值,并从中找出最大的,可以想到优先队列,还要保存下该数的编号,要知道在队首时是a[1].还有处里一种特殊情况,详见代码 总结:这道题并不难,我用了40多分钟,主要前面太急了,一开始并没有想到是优先队列,是一些其他的想法,只要合适一个样例就下手去做,导致有很明显的bug我竟然敲完代

Codeforces Round #318 (Div. 2) A Bear and Elections

优先队列模拟一下就好. #include<bits/stdc++.h> using namespace std; priority_queue<int>q; int main() { int n; scanf("%d",&n); int t; scanf("%d",&t); for(int i = 2; i <= n; i++){ int v; scanf("%d",&v); q.push(v

Codeforces Round #243 (Div. 2) C. Sereja and Swaps(优先队列 暴力)

题目 题意:求任意连续序列的最大值,这个连续序列可以和其他的 值交换k次,求最大值 思路:暴力枚举所有的连续序列.没做对是因为 首先没有认真读题,没看清交换,然后,以为是dp或者贪心 用了一下贪心,各种bug不对. 这次用了一下优先队列,以前用的不多,看这个博客又学了一下 AC代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #i

Codeforces Round #318 (Div. 2) B Bear and Three Musketeers

不要想多了直接暴.对于u枚举a和b,判断一个是否连边,更新答案. #include<bits/stdc++.h> using namespace std; int n,m; const int maxn = 4001; #define PB push_back vector<int> G[maxn]; bool g[maxn][maxn]; int deg[maxn]; const int INF = 0x3f3f3f3f; int main() { //freopen("