CF 348A Mafia

           A. 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 othern - 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: thei-th person wants to playai 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 containsn space-separated integersa1, a2, ..., an(1 ≤ ai ≤ 109) — thei-th number in the list is the number of rounds thei-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 thei-th person play at leastai rounds.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use thecin,cout streams or the%I64d specifier.

Sample test(s)
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-1)名选手。其中第i个人表示想玩a[i]局游戏且不当主持;让求出满足每人要求的最少的局数:

在这道题上我真是栽了一个大跟头啊,刚开始时没有时由于没有彻底理解题意而被wa了n次。接下来又是由于以前没有从来没有在意过64位长整型的几种表示,只顾一味的写“%lld”而没有注意题中警示内容,他们规定64位长整型表示为“%I64d“。特此声明警示一下自己!唉,还是自己练习的题目是太少了啊!加油!!!

注:

附代码如下:

/*题中一些变量注释如下:
      其中 r用老记录满足要求所需的最少局数的;
      至于sum 你懂的,当然是用来记录数据总和的啦;
      还有a[100005]是保存输入的一组数据的;
      max用来记录数据中的最大值的,目的是用来与最后的r值比较,
     如果大于r值,所以就是不满足想比赛max的这个人啦,当然最后就直接输出这个max值啦
*/
#include<stdio.h>
#include<math.h>
int main()
{
    long long i,r,n,sum=0,a[100005],max=-1;
    scanf("%I64d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%I64d",&a[i]);
        sum+=a[i];
        if(a[i]>max)
        {
            max=a[i];
        }
    }
    r=ceil(sum/(n-1.0));
    if(r<max)
     {
         r=max;
     }
     printf("%I64d\n",r);
     return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值