Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A 模擬
連結:戳這裡
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.
題意:
n個人參加競選,每人的得票為ai,現在第一個人想贏,問從其他競選人手中賄賂多少張票可以使自己成為第一
思路:
從小到大列舉賄賂票的數量,判斷是否滿足條件,當人每個人的得票肯定是先從大到小排序
程式碼:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include <ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#define mst(ss,b) memset((ss),(b),sizeof(ss))
#define maxn 0x3f3f3f3f
#define MAX 1000100
///#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef unsigned long long ull;
#define INF (1ll<<60)-1
using namespace std;
int n,x;
int a[110];
int main(){
scanf("%d%d",&n,&x);
n--;
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(int i=0;i<=1001;i++){
int num=0,now=x+i;
for(int j=n;j>=1;j--){
if(a[j]>=now){
num+=a[j]-now+1;
}
}
if(num<=i){
cout<<i<<endl;
return 0;
}
}
return 0;
}
相關文章
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模擬
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B 暴力
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) E DFS
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) D 雙向dp
- Codeforces Round #362 (Div. 2) B 模擬
- Codeforces Round #325 (Div. 2) C 模擬
- Codeforces Round #323 (Div. 2) B 模擬
- Codeforces Round #316 (Div. 2) C 模擬
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] C 數學
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E 三分
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] (ABCDE題解)
- Codeforces Round #362 (Div. 2) C 模擬二叉樹二叉樹
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D 字首字尾維護
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 951 (Div. 2)
- Codeforces Round 955 (Div. 2)
- Codeforces Round 953 (Div. 2)
- Codeforces Round 975 (Div. 2)
- Codeforces Round 976 (Div. 2)
- Codeforces Round 972 (Div. 2)
- Codeforces Round 979 (Div. 2)
- Codeforces Round 982 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)