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. iOS--获取输入字符的第一个字母(汉字则获取拼音的第一个字母)

    - (NSString *)firstCharactor:(NSString *)aString { //转成了可变字符串 NSMutableString *str = [NSMutableStrin ...

  2. Mysql的最佳优化经验20多条

    原文:http://blog.csdn.net/lifuxiangcaohui/article/details/6207801 今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其 ...

  3. 正则表达式使用(Js、Java)

    Js中全局替换,需要在最后加上g(global),并且使用//包围起来 1.全局替换字符+ 和 只替换第一个字符+ alert("2014+03-22++aaaa".replace ...

  4. Java troubleshooting guide

    http://www.oracle.com/technetwork/java/javase/toc-135973.html --不同的 OutOfMemoryError/内存溢出,以及相关的解决

  5. vsphere vcenter 添加域管理员

    选择 vcenter server  管理权限

  6. 比对工具之 BWA 使用方法

    BWA算法简介: BWA-bactrack BWA-SW BWA-MEM BWA安装: # installing BWA .tar.bz2 -C /opt/biosoft/ cd /opt/bioso ...

  7. EL表达式 (详解)(转)

    EL表达式      1.EL简介 1)语法结构        ${expression} 2)[]与.运算符      EL 提供.和[]两种运算符来存取数据.      当要存取的属性名称中包含一 ...

  8. iOS AVAudioRecorder 录音频率、声道、位数配置 wav格式

    iOS AVAudioRecorder 录音频率.声道.位数配置 #pragma mark 录音设置 - (void)setUP_VOICE_RECOARDER { NSError *error = ...

  9. 浅谈线程池(上):线程池的作用及CLR线程池

    原文地址:http://blog.zhaojie.me/2009/07/thread-pool-1-the-goal-and-the-clr-thread-pool.html 线程池是一个重要的概念. ...

  10. jQuery图片延迟加载插件jQuery.lazyload使用方法(转)

    使用方法 1.引用jquery和jquery.lazyload.js到你的页面 <script src="jquery-1.11.0.min.js"></scri ...