One day n friends gathered together to play “Mafia”. During each round of the game some player must be the supervisor and other n - 1 people 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 rounds. What is the minimum number of rounds of the “Mafia” game they need to play to let each person play at least as many rounds as they want?
Input
The first line contains integer 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
In a single line print a single integer — the minimum number of game rounds the friends need to let the i-th person play at least ai rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Example
Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3
一天,n个朋友聚在一起玩“黑手党”。在每一轮比赛中,一些玩家必须是裁判和其他n - 1人参加比赛。对于每个人,我们知道他想成为一名玩家的次数,而不是裁判:要让每个人至少玩多少个回合,他们需要玩多少轮“黑手党”游戏?
因为每个人都要最少玩他们他们想玩的次数,所以游戏的轮数应该大于等于想玩次数最多的次数.因为每一轮都有一个人要当裁判,所以裁判的人数大于等于游戏轮数.
#include <stdio.h>
long long a[100005];
int main()
{
long long max = 0,n,x,y,z,t;
//有多少个人玩
scanf("%lld",&n);
//每个人想玩的次数
for(x=0;x<n;x++)
{
scanf("%lld",&a[x]);
if(a[x]>max)//找出最大次数 ,当成游戏的轮数
{
max = a[x];
}
}
long long num = 0;
//找出有max轮游戏的时候能当裁判的人数
for(x=0;x<n;x++)
{
num += max - a[x];//max-a[x]为a[x]能当裁判的次数
}
long long num1;
if(num<max)//如果能当裁判的人数小于想玩的最多次数,则轮数增加
{
num1 = max - num;//还差多少此裁判才能完成
//每当游戏次数即max加1,则能当裁判的人数增加n-1个
//游戏次数增加的次数等于 相差的次数/(n-1)
if(num1%(n-1))
{
max += num1/(n-1) + 1;
}
else
{
max += num1/(n-1);
}
}
printf("%lld\n",max);
return 0;
}