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. [js学习笔记] 原型链理解

    js中只有对象,包括对象,函数,常量等. prototype 只有函数里有这个属性. 对象里可以设置这个属性,但是没这个属性的意义 prototype指向一个对象,可以添加想要的方法. 该对象里有一个 ...

  2. angular-bootstrap ui-date组件问题总结

    使用angular框架的时候,之前用的时间控件是引入My97DatePicker组件实现的,但是因为 1.My97DatePicker样式不太好看以及偶尔会出现底部被遮盖的情况.点击不可编辑input ...

  3. nmap扫描某段网络连通性

    nmap -v -sP 10.0.10.0/24 进行ping扫描,打印出对扫描做出响应的主机,不做进一步测试(如端口扫描或者操作系统探测): nmap -sP 192.168.1.0/24 仅列出指 ...

  4. 【专章】dp入门

    动态规划(简称dp),可以说是各种程序设计中遇到的第一个坎吧,这篇博文是我对dp的一点点理解,希望可以帮助更多人dp入门. ***实践是检验真理的唯一标准,看再多文章不如自己动手做几道!!!*** 先 ...

  5. The Super Powers

    The Super Powers Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [Subm ...

  6. Ionic3学习笔记(一)安装、项目结构与常用命令

    本文为原创文章,转载请标明出处 目录 安装 项目结构 常用命令 1. 安装 安装Cordova.Ionic npm install -g cordova ionic 创建一个新项目,有blank.ta ...

  7. Spring Boot Starter 介绍

    http://www.baeldung.com/spring-boot-starters 作者:baeldung 译者:http://oopsguy.com 1.概述 依赖管理是任何复杂项目的关键部分 ...

  8. java多线程编程题之连续打印abc的几种解法

    一道编程题如下: 实例化三个线程,一个线程打印a,一个打印b,一个打印c,三个线程同时执行,要求打印出6个连着的abc 题目分析: 通过题意我们可以得出,本题需要我们使用三个线程,三个线程分别会打印6 ...

  9. 吾八哥学Python(三):了解Python基础语法(上)

    学习一门开发语言首先当然是要熟悉它的语法了,Python的语法还算是比较简单的,这里从基础的开始了解一下. 标识符1.第一个字符必须是字母表中字母或下划线'_'.2.标识符的其他的部分有字母.数字和下 ...

  10. Gradle sync failed 异常

    今天开发过程中出现如下异常 Gradle sync failed: Connection timed out: connect. If you are behind an HTTP proxy, pl ...