A. Mafia

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/348/problem/A

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 - 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: 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 ai rounds.

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

3
3 2 2

Sample Output

4

HINT

题意

有n个人,在玩一个游戏,游戏表示每局都必须有个管理员参加

告诉你,每个人想当多少局玩家,然后让你求,最少多少局游戏,才能满足题意!

题解:

贪心就好了,类似厨师煮饼那道题一样

max(max_num,sum/(n-1));

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** ll a[maxn];
ll sum=;
ll mx=;
int main()
{
int n=read();
for(int i=;i<=n;i++)
a[i]=read(),sum+=a[i],mx=max(a[i],mx);
n=n-;
ll ans;
ans=sum/n;
if(sum%n!=)
ans++;
cout<<max(mx,ans)<<endl;
}

Codeforces Round #202 (Div. 1) A. Mafia 贪心的更多相关文章

  1. Codeforces Round #202 (Div. 1) A. Mafia 推公式 + 二分答案

    http://codeforces.com/problemset/problem/348/A A. Mafia time limit per test 2 seconds memory limit p ...

  2. Codeforces Round #202 (Div. 2)

    第一题水题但是wa了一发,排队记录下收到的25,50,100,看能不能找零,要注意100可以找25*3 复杂度O(n) 第二题贪心,先找出最小的花费,然后就能得出最长的位数,然后循环对每个位上的数看能 ...

  3. Codeforces Round #202 (Div. 2) B,C,D,E

    贪心 B. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  4. Codeforces Round #382 (Div. 2)B. Urbanization 贪心

    B. Urbanization 题目链接 http://codeforces.com/contest/735/problem/B 题面 Local authorities have heard a l ...

  5. Codeforces Round #164 (Div. 2) E. Playlist 贪心+概率dp

    题目链接: http://codeforces.com/problemset/problem/268/E E. Playlist time limit per test 1 secondmemory ...

  6. Codeforces Round #180 (Div. 2) B. Sail 贪心

    B. Sail 题目连接: http://www.codeforces.com/contest/298/problem/B Description The polar bears are going ...

  7. Codeforces Round #192 (Div. 1) A. Purification 贪心

    A. Purification Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/329/probl ...

  8. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  9. Codeforces Round #374 (Div. 2) B. Passwords 贪心

    B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...

随机推荐

  1. 不相交集ADT--数组实现

    不相交集是解决等价问题的一种有效的数据结构,之所以称之为有效是因为,这个数据结构简单(几行代码,一个简单数组就可以搞定),快速(每个操作基本上可以在常数平均时间内搞定). 首先我们要明白什么叫做等价关 ...

  2. 4-Python数据类型之元组-字符串

    目录 1 元组概念 1.1 元祖的特点 1.2 元组的定义 1.3 元组的访问 1.4 元组的查询 2 命名元组 3 字符串 3.1 字符串的基本操作 3.1.1 字符串的访问 3.1.2 字符串的拼 ...

  3. Python3 动态导入模块的两种方式

    动态导入模块就是只知道str类型的模块名字符串,通过这个字符串导入模块 需要导入的模块: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:C ...

  4. 用C#实现通过串口对设备的数据采集--Server层

    今天中午没睡午觉,头昏眼花的,实在写不了代码,把这几天写的Server层数据采集的程序整理了一下. WatrLevelDataCollectServer.cs using System; using ...

  5. LNMP结合discuz的配置

    一.安装discuz 配置参照LAMP结合discuz的第一部分 不要忘记了 添加hosts~!!!! ===============我是分割线.========================== ...

  6. C++——map注意事项

    1. C++标准模块库STL中提供了两种基本的关联容器:set和map.其内部实现是都是采用红黑树,但不同的是,set中结点存储的是键值,map中结点存储的是<key,value>的键值对 ...

  7. input只读属性 设置和移除 选择数字

    设置只读属性 $('#stage').attr("readonly", "readonly"); 移除 只读属性  $("input").r ...

  8. 用dom4j操作xml文件

    XML的全称是eXtensible Markup Language,即“可扩展标记语言”.XML文件的作用主要是数据存储,文件配置,数据传输. html与xml的区别是:①html语法松散,xml语法 ...

  9. mysql视图学习总结(转)

    一.使用视图的理由是什么?1.安全性.一般是这样做的:创建一个视图,定义好该视图所操作的数据.之后将用户权限与视图绑定.这样的方式是使用到 了一个特性:grant语句可以针对视图进行授予权限.2.查询 ...

  10. curd 插件

    1. Django项目启动 自动加载文件 制作启动文件 . 注册strak 在apps.py 类里面增加如下 def ready(self): from django.utils.module_loa ...