A. Mafia
time limit per test
memory limit per test
input
output
n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai
Input
n (3 ≤ n ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the i-th number in the list is the number of rounds the i-th person wants to play.
Output
i-th person play at least airounds.
%lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64dspecifier.
Sample test(s)
input
3 3 2 2
output
4
input
4 2 2 2 2
output
3
Note
http://en.wikipedia.org/wiki/Mafia_(party_game).
这题如果硬解没思路,但是判断一个答案就是很简单。
然后你懂得。。
因为用了int惨遭Hack,各种NC。。。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n;
ll a[MAXN];
int main()
{
cin>>n;
For(i,n) cin>>a[i];
ll k=0;
For(i,n) k=max(k,a[i]);
ll t=0;
For(i,n) t+=k-a[i];
if (t>=k) {cout<<k<<endl;return 0; }
else
{
double p=((double)(k-t))/((double)(n-1));
k+=ceil(p);
cout<<k<<endl;
}
return 0;
}