E - Decrease (Judge ver.)


Time limit : 2sec / Memory limit : 256MB

Score : 600 points

Problem Statement

We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N−1 or smaller. (The operation is the same as the one in Problem D.)

  • Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.

It can be proved that the largest element in the sequence becomes N−1 or smaller after a finite number of operations.

You are given the sequence ai. Find the number of times we will perform the above operation.

Constraints

  • 2≤N≤50
  • 0≤ai≤1016+1000

Input

Input is given from Standard Input in the following format:

N
a1 a2 ... aN

Output

Print the number of times the operation will be performed.


Sample Input 1

Copy
4
3 3 3 3

Sample Output 1

Copy
0

Sample Input 2

Copy
3
1 0 3

Sample Output 2

Copy
1

Sample Input 3

Copy
2
2 2

Sample Output 3

Copy
2

Sample Input 4

Copy
7
27 0 0 0 0 0 0

Sample Output 4

Copy
3

Sample Input 5

Copy
10
1000 193 256 777 0 1 1192 1234567891011 48 425

Sample Output 5

Copy
1234567894848
模拟一下就可以了
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define ios() ios::sync_with_stdio(false)
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll n,k,x,m;
priority_queue<ll>q;
int main()
{
ios();
scanf("%lld",&n);
for(int i=;i<=n;i++)
{
scanf("%lld",&x);
q.push(x);
}
k=;
while(q.top()+k>=n)
{
ll ans=q.top()+k;
q.pop();
m=ans/n;
ans-=m*n;
k+=m;
q.push(ans-k);
}
printf("%lld\n",k);
return ;
}

Atcoder AtCoder Regular Contest 079 E - Decrease (Judge ver.)的更多相关文章

  1. 【贪心】AtCoder Regular Contest 079 E - Decrease (Judge ver.)

    每次将最大的数减到n以下,如此循环直到符合题意. 复杂度大概是n*n*log?(?). #include<cstdio> #include<iostream> #include ...

  2. 【构造】AtCoder Regular Contest 079 D - Decrease (Contestant ver.)

    从n个t变化到n个t-1,恰好要n步,并且其中每一步的max值都>=t,所以把50个49当成最终局面,从这里开始,根据输入的K计算初始局面即可. #include<cstdio> # ...

  3. Atcoder At Beginner Contest 068 D - Decrease (Contestant ver.)

    D - Decrease (Contestant ver.) Time limit : 2sec / Memory limit : 256MB Score : 600 points Problem S ...

  4. 【构造】AtCoder Regular Contest 079 F - Namori Grundy

    对每个点的取值都取最小的可能值. 那个图最多一个环,非环的点的取值很容易唯一确定. 对于环上的点v,其最小可能取值要么是mex{c1,c2,...,ck}(ci这些是v直接相连的非环点)(mex是). ...

  5. AtCoder Regular Contest 079

    C题,刚开始以为遍历整个树,后来发现二重循环判断就行了 #include<map> #include<set> #include<cmath> #include&l ...

  6. Decrease (Judge ver.)

    题目描述 We have a sequence of length N consisting of non-negative integers. Consider performing the fol ...

  7. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  8. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  9. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

随机推荐

  1. Linux系统编程——进程间通信:信号中断处理

    什么是信号? 信号是 Linux 进程间通信的最古老的方式.信号是url=474nN303T2Oe2ehYZjkrggeXCaJPDSrmM5Unoh4TTuty4wSgS0nl4-vl43AGMFb ...

  2. Windows改动cmd字符集

    在中文Windows系统中,假设一个文本文件是UTF-8编码的,那么在CMD.exe命令行窗体(所谓的DOS窗体)中不能正确显示文件里的内容.在默认情况下,命令行窗体中使用的代码页是中文或者美国的,即 ...

  3. android selector设置button点击效果(具体)以及常见问题

    button的点击效果学习起来其实比較easy,此点对开发人员来说也是使用的比較频繁的一个知识点,与它相关的还有编辑框的获取焦点时改变背景颜色.选择button选择时改变字体颜色等等.这些其实都是用到 ...

  4. Visual Code的调试

    Run 'Debug: Download .NET Core Debugger' in the Command Palette or open a .NET project directory to ...

  5. Gym - 100625G Getting Through 计算几何+并查集

    http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...

  6. POJ2823 单调队列

    POJ2823 http://poj.org/problem?id=2823 最基础的单调队列,说是数据结构,其实就是一种更新数组数据的方法. 之前还准备用deque,超时了,直接head,tail快 ...

  7. Sqoop-1.4.6工具import和export使用详解(官网)

    不多说,直接上干货! 1.Sqoop Import (进入官网) 因为,sqoop的使用方式是: sqoop COMMAND  ARGS. 以下是  sqoop COMMAND  ARGS 以下是   ...

  8. java读取jpg图片旋转按比例缩放

    //入口 public static BufferedImage constructHeatWheelView(int pageWidth, int pageHeight, DoubleHolder ...

  9. js生成验证码并验证的登录页面

    <!Doctype html> <html> <head> <meta charset="utf-8"/> <title> ...

  10. Coderfroces 862 C. Mahmoud and Ehab and the xor

    C. Mahmoud and Ehab and the xor Mahmoud and Ehab are on the third stage of their adventures now. As ...