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

Hint

In first sample test we can increase factor of first badge by 1.

In second sample test we can increase factors of the second and the third badge by 1.

题意:给一串数字,使得他们每个都不一样,需要增加几....

题解;先输入的时候算出和,然后排序,接下来循环,如果后一个等于前一个,a[i]++,如果前一个大于后一个,a[i]加上前一个减去后一个的再加上1,这样,他就不会个前面的相等.....

最后把他们的和算出来,求两个和的差就是答案...

代码如下:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int a[];
int main()
{
int n;
while(scanf("%d",&n)==)
{
int sum1=,sum2=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum1+=a[i];
}
sort(a+,a+n+);
sum2=a[];
for(int i=;i<=n;i++)
{
if(a[i]==a[i-])
a[i]++;
else if(a[i]<a[i-])
a[i]+=a[i-]-a[i]+;
sum2+=a[i];
}
printf("%d\n",sum2-sum1);
}
return ;
}

第一次比赛的 C题 (好后面才补的....) CodeForces 546B的更多相关文章

  1. UVA 10970 第一次比赛 D题 (后面才补的)

    Mohammad has recently visited Switzerland. As heloves his friends very much, he decided to buy somec ...

  2. 小埋的Dancing Line之旅:比赛题解&热身题题解

    答疑帖: 赞助团队:UMR IT Team和洛谷大佬栖息地 赛后题解:更新了那两道练手题的题解 赛时公告,不过一些通知也可能在团队宣言里发出 如果各位发现重题,请将你认为重复的题目链接连同这次比赛的题 ...

  3. 差分模版题(需理解才明白)AT2442 フェーン現象 (Foehn Phenomena)

    https://www.luogu.org/problemnew/show/AT2442 #include <bits/stdc++.h> #define read read() #def ...

  4. sdut oj 1163 C语言实验——排列 (当初不会递归生成排列,这个题目现在才补上 刘汝佳给出了写法 *【模板】 当然有生成全排列的函数存在 )

    C语言实验——排列 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 有4个互不相同的数字,请按序输出由其中三个不重复数字组成的排列 ...

  5. codeforces 1425E,一万种情况的简单题

    大家好,欢迎阅读codeforces专题. 我们今天选中的是codeforces 1425场比赛的E题,这是一场印尼多校联合的ICPC的练习赛.ACM赛制,难度也比较近似.我们今天选择的是其中的一道M ...

  6. 2015 湘潭大学程序设计比赛(Internet)部分题解,其中有一个题与NYOJ1057很像,贪心过~~

    仙剑奇侠传                 祝玩的开心                                                                          ...

  7. CF-补题1

    CF-补题1 1.CodeForces 735C    题意:n个人淘汰赛,两个人可以比赛的条件是:两人打过的场数之差绝对值<2.求冠军最多可以打多少场.  总结:看了题解,转换一下思路.求n个 ...

  8. 【线性规划与网络流 24题】已完成(3道题因为某些奇怪的原因被抛弃了QAQ)

    写在前面:SDOI2016 Round1滚粗后蒟蒻开始做网络流来自我拯救(2016-04-11再过几天就要考先修课,现在做网络流24题貌似没什么用←退役节奏) 做的题目将附上日期,见证我龟速刷题. 1 ...

  9. 省选训练赛第4场D题(多米诺骨牌)

    题目来自FZU2163 多米诺骨牌 Time Limit: 1000 mSec    Memory Limit : 32768 KB  Problem Description Vasya很喜欢排多米诺 ...

随机推荐

  1. cat命令的作用

    1.显示文件内容,如more的功能. 使用方法: cat  filename. 注:cat,无论文件多长,一次性全部显示:more,一次只显示一个屏幕高度的内容. 2.创建文件,如touch功能. 使 ...

  2. JPasswordField 中得到的字符数组转化为字符串(密码乱码问题)

    转载自:http://blog.csdn.net/skl_tz/article/details/9009805 JPasswordField 用作密码的输入框,似乎很方便,但是,为了得到输入的内容,一 ...

  3. java 的文件读取操作

    /** * @param filePath 文件的全路径 * 返回我们读取到的文件内容 * **/ public static String readFile(String filePath) { F ...

  4. 机房收费系统之uml图——初版

    说起uml图,在我心中最难的当属类图无疑.虽然敲了三层的小例子,但真正让把三层和uml图结合起来,并且还要考虑设计模式的时候,总是让人有一种无从下手的感觉,不过还好,通过这半个多月的思考与探索(竟然用 ...

  5. Storm累计求和进群运行代码

    打成jar包放在主节点上去运行. import java.util.Map; import backtype.storm.Config; import backtype.storm.StormSubm ...

  6. python15-day1课堂随机

    print("Hello world") #变量定义:一个在内存储存数据的容器#意义:为什么有变量,因为它保存程序执行的中间结果或状态以供后面的低吗进行调用 day1 = 200+ ...

  7. JavaScript作用域(链)学习笔记

    作用域是javascript老生常谈的问题,在面试题中也经常出现.此文记录本人对js作用域的理解.从以下三个方面深入探讨js作用域和js作用域链. 1.什么是作用域? 2.什么是作用域链? 3.常见面 ...

  8. MongoDB - MongoDB CRUD Operations, Query Documents, Project Fields to Return from Query

    By default, queries in MongoDB return all fields in matching documents. To limit the amount of data ...

  9. CI框架程序--本地调试之后部署新浪SAE

    前几天给朋友写了个简单的网站, 想想还是部署到服务器上让朋友看一下效果! 用CI框架写的,有个SAE新浪云的账号,可以用!就部署到上面去了!途中遇到了一些问题!一一解决了! 在这里分享一下 供遇到这些 ...

  10. Js中把JSON字符串转换为JSON对象(eval()、new Function())

    在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析. 第一种解析方式:使用eval函数来解析,并且使用j ...