Description

Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin.

For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors.

Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness.

Input

First line of input consists of one integer n (1 ≤ n ≤ 3000).

Next line consists of n integers ai (1 ≤ ai ≤ n), which stand for coolness factor of each badge.

Output

Output single integer — minimum amount of coins the colonel has to pay.

Sample Input

Input
4
1 3 1 4
Output
1
Input
5
1 2 3 2 5
Output
2

#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std;

#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 5000005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
const int mod = 1e9+7;
#define LL __int64
int n,a[3005];
int main()
{
  int i,j,ans;
  while(~scanf("%d",&n))
  {
    ans = 0;
    int sum1 = 0,sum2 = 0;
    for(i = 1; i<=n; i++)
    {
      scanf("%d",&a[i]);
      sum1+=a[i];
    }
    sort(a+1,a+1+n);
    sum2 = a[1];
    for(i = 2; i<=n; i++)
    {
      if(a[i] == a[i-1])
      a[i]++;
      else if(a[i]<a[i-1])
      a[i] +=(a[i-1]-a[i])+1;
      sum2+=a[i];
    }
    printf("%d\n",sum2-sum1);
  }

return 0;
}


CodeForces 546B C(Contest #1)的更多相关文章

  1. Codeforces 659B Qualifying Contest【模拟,读题】

    写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...

  2. 【codeforces 546B】Soldier and Badges

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. codeforces E. The Contest(最长上升子序列)

    题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...

  4. codeforces 659B Qualifying Contest

    题目链接:http://codeforces.com/problemset/problem/659/B 题意: n个人,m个区.给出n个人的姓名(保证不相同),属于的区域,所得分数.从每个区域中选出成 ...

  5. 【37.74%】【codeforces 725D】Contest Balloons

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. CodeForces 474B E(Contest #1)

    题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...

  7. 第一次比赛的 C题 (好后面才补的....) CodeForces 546B

    Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...

  8. codeforces 546B

    Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...

  9. Codeforces April Fools Contest 2017

    都是神题,我一题都不会,全程听学长题解打代码,我代码巨丑就不贴了 题解见巨神博客 假装自己没有做过这套

随机推荐

  1. CSS3_边框属性之圆角的基本图形案例

    一.正方形 div{ background:#F00; width:100px; height:100px;}   二.长方形 div{background:#F00;width:200px;heig ...

  2. 激活MyEclipse 6.5方法-通过一段Java程序生成激活码

    在MyEclipse中新建一个Java类,名为MyEclipseKeyGen,将下面的Java代码拷贝到MyEclipseKeyGen类中,先修改变量subscriber的值,然后运行程序即可获得Su ...

  3. js 删除多个相同name元素。

    var obj = document.getElementsByName("abc"); for(var i = 0;i<(obj.length) * 2;i++){ obj ...

  4. SVM中图像常用的HOG特征描述及实现

    转摘网址:http://www.cnblogs.com/tiandsp/archive/2013/05/24/3097503.html Hog参考网址:http://www.cnblogs.com/t ...

  5. Openvpn 安装简述

    1.固定本地IP地址 vim /etc/sysconfig/network-scripts/ifcfg-eth0 2.同步时间.安装ntpd yum  install ntpddate netupda ...

  6. servlet 文件上传简易版

    package cn.itcast.servlet; import java.io.File;import java.io.IOException;import java.util.List; imp ...

  7. The Network Adapter could not establish the connection问题研究

    最近一个项目会报上述错误,但也不是经常发生,所以很难跟踪,影响不是很大,但每次看到日志中这个错误就会不舒服,还是要想办法解决才是. 错误提示信息很明确是网络适配器不能创建连接. 查了很多资料,并且Or ...

  8. 栅栏 CyclicBarrier

    java.util.concurrent.CyclicBarrier 类是一种同步机制,它能够对处理一些算法的线程实现同步.换句话讲,它就是一个所有线程必须等待的一个栅栏,直到所有线程都到达这里,然后 ...

  9. JavaScript实现五子棋的界面设计

    五子棋的界面设计包括绘制棋盘.绘制棋子及黑白棋轮流落子. 涉及的知识点主要有canvas绘制直线.设置画笔颜色:canvas画圆.填充渐变色 1.绘制棋盘 先设定棋盘的宽.高:然后利用for循环,根据 ...

  10. HDUoj-------(1128)Self Numbers

    Self Numbers Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...