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: 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) — thei-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.

Examples
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).

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<queue>
#include<list>
#include<stack>
#include<queue>
using namespace std;
const int maxn=100010;
long long num[maxn],n;
bool judge(long long mid){long long ans=0;for(int i=1;i<=n;++i){if(num[i]>mid)return false;ans=ans+mid-num[i];}return ans>=mid;
}
int main()
{long long ans=0,left=0,right=0;scanf("%lld",&n);for(int i=1;i<=n;++i){scanf("%lld",&num[i]);right+=num[i];}while(left<=right){long long mid=(left+right)>>1;if(judge(mid)){ans=mid;right=mid-1;}else {left=mid+1;}}printf("%lld\n",ans);return 0;
}

codeforces202A. Mafia【二分】相关推荐

  1. 【CodeForces - 349C】Mafia(思维模拟,优秀的二分)

    题干: One day n friends gathered together to play "Mafia". During each round of the game som ...

  2. Codeforces Round #202 (Div. 1) A. Mafia 【二分】

    A. Mafia time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  3. codeforces Mafia

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

  4. CodeForces - 348A E - Mafia

    One day n friends gathered together to play "Mafia". During each round of the game some pl ...

  5. 算法图解/二分查找/简单查找/选择排序/递归算法/快速排序算法/

    大 O 表示法 大 O 表示法在讨论运行时间时,log 指的都是 log2 大 O 表示法指出了算法有多快,让你能够比较操作数,它指出了算法运行时间的增速,而并非以秒为单位的速度. 大 O 表示法指出 ...

  6. 分治算法的设计思想(二分检索、二分归并排序)

    分治策略思想: 将原问题划分或者归结为规模较小的子问题. 递归或迭代求解每一个问题. 将子问题的解综合得到原问题的解. 性质: 子问题与原问题具有相同的性质. 子问题的求解彼此独立. 划分时子问题的规 ...

  7. LeetCode简单题之二分查找

    题目 给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1. 示例 1: 输入: n ...

  8. 二分查找模板全面总结

    二分查找 二分法的引入 情形1 1.X的平方根 2.搜索旋转排序数组 情形2 1.第一个错误的版本 2.寻找峰值 3.寻找旋转排序数组中的最小值 情形3 在排序数组中查找第一个和最后一个位置 当遇到查 ...

  9. [C] [二分] C语言实现快速排序

    为了以防万一有人想不开想手撕快排呢?比如我. 通过快排来理解二分思想 什么是快排? 快排的思想不难,理解好递归很重要. 什么是递归? 递归,就是在运行的过程中调用自己. 构成递归需具备的条件: 子问题 ...

最新文章

  1. 专家认为自动驾驶汽车需要很多年的五个原因
  2. dwa的区别 teb_teb_local_planner安装及使用
  3. leetcode_486. Predict the Winner
  4. DataSet中的relation
  5. swift和oc区别----属性部分(参考官方swift2.1文档)
  6. oracle那些基本知识
  7. c++ winpcap开发(4)
  8. 通信原理matlab实验课程设计,通信原理matlab课程设计报告
  9. Spring Boot学习总结(28)—— springboot连接postgresql 指定模式Schema
  10. vivo应用商店服务器,vivo应用商店
  11. plsql连接mysql教程_plsql直连数据库教程
  12. silvaco的石墨烯fet仿真_COMSOL Multiphysics多物理场仿真光电学习必看的内容
  13. Android 显示历史搜索记录
  14. 手机计算机错误格式,手机内存卡提示文件格式错误怎么办【解决方法】
  15. Linux命令行与shell脚本编程大全第三版 学习笔记
  16. jQuery遍历对象、数组、集合
  17. 币圈小白必读的6本加密货币书籍
  18. 算法训练一(贪心、二分)(含解题思路)(上)
  19. 功能: Form窗口最大化时,控件相对位置变化的问题 (学习日记2016-12-23)
  20. [语音处理] .flac文件转.wav文件

热门文章

  1. eclipse怎么搜索关键字? eclipse查找关键字的技巧
  2. 转发:网桥介绍——好理解
  3. 04_Initial Design/Floorplan实操2021-09-08上午
  4. FreeSWITCH设置日志大小
  5. 从玩法、叙事、主题三个角度浅要谈谈《死亡搁浅》的好与坏
  6. 2022秋季 电影&书单
  7. 图像灰度、亮度、强度区分
  8. invalid non-printable character U+200D
  9. 伤感 html代码,让对方瞬间心酸的文案,伤感入体,痛彻心扉!
  10. 新手入坑GMSSL(一)Windows下编译GMSSL并生成CA证书