A. Elections

Awruk is taking part in elections in his school. It is the final round. He has only one opponent — Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives ai votes for Elodreip, than he will get exactly kai votes from this person. Of course 0≤kai holds.

Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows a1,a2,…,an — how many votes for Elodreip each student wants to give. Now he wants to change the number k to win the elections. Of course he knows that bigger k

means bigger chance that somebody may notice that he has changed something and then he will be disqualified.

5
1 1 1 5 1

OutputCopy

5

InputCopy

5
2 2 3 2 2

OutputCopy

5

#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
int a[maxn];
int n;
int deal(int x){
int sum=0;
for(int i=0;i<n;i++){
if(a[i]>x)
return 0;
sum+=a[i];
}
return sum * 2 < x*n;
}
int main(){
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
int count=1;
while(!deal(count)){
count++;
}
cout<<count<<endl;
//system("pause");
return 0;
}

python代码

n = int(input())
arr = list(map(int,input().strip().split()))
k = max(arr)
while True:
s = sum(arr)
if k*n > 2*s:
print(k)
break
else:
k+=1
Tagged with: |