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. nodejs(一) 简单登录验证 使用mongoose 操作MongoDB

    ---恢复内容开始--- 开发使用webstorm 9  新建nodejs+express 项目 newfarmer 文章目录 配置Mongoose 创建目录及文件 插入数据,POST提交JSON增加 ...

  2. React Native中常见操作

    一.如何将项目安装到iOS手机上? 1.将手机于电脑连接好,并将Xcode打开连接上手机 2.在General  -> Team 下添加自己的Apple ID. 3.改本地的IP地址: 4.点击 ...

  3. 剑指Offer07 斐波那契数列

    /************************************************************************* > File Name: 07_Fibona ...

  4. codeforces 677C C. Vanya and Label(组合数学+快速幂)

    题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. python15-day1课堂随机

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

  6. nginx二级域名配置

    CentOs下nginx二级域名配置 域名配置文件 命名规则:XXX.域名信息.conf 配置文件路径:etc/nginx/conf.d/xxxx.conf 配置文件内容:server { liste ...

  7. Asp.Net-创建网站的快捷方式到桌面,开始菜单,收藏夹

            /// <summary>         /// 创建快捷方式         /// </summary>         /// <param na ...

  8. R语言快速入门

    R语言是针对统计分析和数据科学的功能全面的开源语言,R的官方网址:http://www.r-project.org/  在Windows环境下安装R是很方便的 R语言的两种运行模式:交互模式和批处理模 ...

  9. C#_数组

     数组是相同数据类型的元素按一定顺序排列的集合,然后用一个变量名进行命名.新建控制台程序,声明一个静态方法 using System; using System.Collections.Gener ...

  10. DWZ(JUI) 教程 左侧栏默认是关闭状态的问题

    DWZ(JUI) 教程 左侧栏默认是关闭状态的问题,初始化是全屏状态,只需简单处理就可以了 $(function(){ DWZ.init("dwz.frag.xml", { log ...