当前位置:网站首页>2017/7/9

2017/7/9

2021-09-15 05:07:49 lhclqslove

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
  • 1.
  • 2.
output
4
          
  • 1.
input
4
2 2 2 2
  • 1.
  • 2.
output
3
          
  • 1.
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).

 

 brief introduction :n When playing a game alone, one person should host the game every time , give n How many times each person wants to play , Ask at least how many rounds can satisfy everyone's desire ,
         
  • 1.
 Answer key : The first i The number of times you want to play a[i] Think it's a[i] I want to play once, so it's easy to understand , Each round can reduce n-1 personal ,
         
  • 1.
 So the a[i] Sum up to get sum, And then look sum%(n-1) Is it 0, Not for 0 Add ans= sum/(n-1)+1; by 0  Words ans= sum/(n-1), But that's not enough , It is possible that a player wants to play a lot , therefore ans Must also work with a[i] Compare the maximum value of , The larger one is the answer :
         
  • 1.
 The code is as follows :
         
  • 1.
#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; 
    
} 
 
          
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.

Topic link :http://codeforces.com/contest/349/problem/C

 
 
 
 

版权声明
本文为[lhclqslove]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/09/20210909115113539j.html

随机推荐