2017/7/9

C. Mafia
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day 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 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 airounds.

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 %I64dspecifier.

Examples
input
3
3 2 2
output
4
input
4
2 2 2 2
output
3
Note

You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times:http://en.wikipedia.org/wiki/Mafia_(party_game).

简介:n个人玩游戏每次都要有一个人来主持游戏,给出n个人每人的想玩次数,问最少多少轮能满足所有人的渴望,
题解:把第i个想玩的次数a[i]认为是a[i]个人想玩一次这样就好理解了,每玩一轮可以减少n-1个人,
所以把a[i]求和得sum,然后看sum%(n-1)是否为0,不为0加ans= sum/(n-1)+1;为0 的话ans= sum/(n-1),但这样还不够,应为有可能某一个想玩的次数非常多,所以ans还必须与a[i]的最大值做比较,取较大的就是答案:
代码如下:
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include<iostream>
#define ll long long 
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int b[maxn];
ll sum=0; 
int n;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]); 
        sum+=a[i]; 
    } 
    sort(a,a+n);
    ll ans=sum/(n-1);
    if(sum%(n-1)!=0)
    {
        ans=ans+1; 
    } 
    ans=ans<a[n-1]?a[n-1]:ans;
    cout<<ans<<endl; 
    
} 
 

题目链接:http://codeforces.com/contest/349/problem/C

原文地址:https://www.cnblogs.com/lhclqslove/p/7142500.html