C - Mafia

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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 %I64d specifier.

Sample Input

Input
3
3 2 2
Output
4
Input
4
2 2 2 2
Output
3

Hint

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个小朋友玩游戏,这个游戏每轮必须有一个人坐庄(不能玩游戏),其他人参与游戏,每个小朋友都想当ai次玩游戏的人,问
至少多少轮游戏才能满足要求 初步思路:二分,二分的条件就是将所有的小朋友的坐庄的次数和玩游戏的次数和总共需要坐庄的次数比较 #错误:INF开小了
*/
#include <bits/stdc++.h>
#define INF 1e13
using namespace std;
long long a[];
long long maxn=-;
int n;
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&n);
for(int i=;i<n;i++){
cin>>a[i];
maxn=max(maxn,a[i]);
}
long long l=maxn,r=INF,mid,res,ans=-;
while(l<=r){
mid=(l+r)>>;
res=;
for(int i=;i<n;i++){
res+=mid-a[i];
}
if(res>=mid){
ans=mid;
r=mid-;
}else{
l=mid+;
}
}
cout<<ans<<endl;
return ;
}

349B - C. Mafia的更多相关文章

  1. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  2. [BZOJ1163][BZOJ1339][Baltic2008]Mafia

    [BZOJ1163][BZOJ1339][Baltic2008]Mafia 试题描述 匪徒准备从一个车站转移毒品到另一个车站,警方准备进行布控. 对于每个车站进行布控都需要一定的代价,现在警方希望使用 ...

  3. Codeforces Gym 100733H Designation in the Mafia flyod

    Designation in the MafiaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  4. codeforces Mafia

    /* * Mafia.cpp * * Created on: 2013-10-12 * Author: wangzhu */ /** * 每个人都想玩若干场,求至少需要玩几场才可以满足大家的需求. * ...

  5. 1339 / 1163: [Baltic2008]Mafia

    1163: [Baltic2008]Mafia Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 96  Solved: 60[Submit][Statu ...

  6. 【CF587D】Duff in Mafia 二分+前缀优化建图+2-SAT

    [CF587D]Duff in Mafia 题意:给你一张n个点m条边的无向图,边有颜色和边权.你要从中删去一些边,满足: 1.任意两条删掉的边没有公共的顶点.2.任意两条剩余的.颜色相同的边没有公共 ...

  7. Codeforces 349C - Mafia

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

  8. Codeforces 349B - Color the Fence

    349B - Color the Fence 贪心 代码: #include<iostream> #include<algorithm> #include<cstdio& ...

  9. Codeforces Round #202 (Div. 1) A. Mafia 贪心

    A. Mafia Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/348/problem/A D ...

随机推荐

  1. display:flex css

    本文介绍下flex的用法和属性 这个一个自适应的3列盒子 <div class="flex"> <div style="background-color ...

  2. [js高手之路] html5 canvas动画教程 - 实时获取鼠标的当前坐标

    有了前面的canvas基础之后,现在开始就精彩了,后面写的canvas教程都是属于综合应用,前面已经写了常用的canvas基础知识,参考链接如下: [js高手之路] html5 canvas系列教程 ...

  3. Tomcat的四种基于HTTP协议的Connector性能比较

    Tomcat从5.5版本开始,支持以下四种Connector的配置分别为: <Connector port="8081" protocol="org.apache. ...

  4. 用python的TK模块实现猜成语游戏(附源码)

    说明:本游戏使用到的python模块有tkinter,random,hashlib:整个游戏分为四个窗口,一个进入游戏的窗口.一个选关窗口.一个游戏进行窗口和一个游戏结束的窗口. 源码有两个主要的py ...

  5. bzoj1968 COMMON 约数研究

    Input只有一行一个整数 N(0 < N < 1000000).Output只有一行输出,为整数M,即f(1)到f(N)的累加和.Sample Input 3 Sample Output ...

  6. bzoj2330(差分约束)

    题解:这道题是练差分约束的一道好题目吧,我具体在代码中注释,这样更加好理解, 为什么求最长路呢?因为这样保证了满足条件,如果存在正权环,就表示无解,就是 正权环之间不断要更多的糖果才行. #inclu ...

  7. Android01-布局篇

    在Android中,共有五种布局方式,分别是:LinearLayout(线性布局),FrameLayout(帧布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局) ...

  8. web前端面试官挖的那些坑(js)

    题目1: function Foo() { getName = function () { alert (1); }; return this; } Foo.getName = function () ...

  9. 错误:Cannot set property 'innerHTML' of null

    360浏览器代码编辑器里提示错误:Cannot set property 'innerHTML' of null 原因是代码执行时要调用的内容不存在

  10. ajax请求service报405错误 - 【服务器不允许的方法】

    产生原因:web服务器找不到service方法处理请求. 检查方向: ① service方法名称写错 ② service方法参数类型与标准不一致 ③ service方法异常,返回值类型和标准不一致 ④ ...