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. Android学习笔记⑥——UI组件的学习ImageView相关

    ImageView是集成了View的组件,它的主要工作就是显示一些图片啊,虽然他的用法一句话概括了,但是我觉得学起来应该不会太简单,正所谓 短小而精悍么 :) ImageView 派生了 ImageB ...

  2. 通过maven添加quartz

    pom.xml中相关dependency信息 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <depen ...

  3. linux初学 :linux 常用命令(二)

    压缩和解压命令 gzip/guzip   zip/unzip   tar gzip和gunzip一般可用参数是-r,例: gzip test.txt 压缩文件 gzip -r test 压缩所有tes ...

  4. ligerui grid行编辑示例

    <%@ page contentType="text/html; charset=UTF-8" %> <% String path = request.getCo ...

  5. 修改tomcat浏览器地址栏图标

    1.准备一张jpg格式的图片 2.去百度:ico图标在线制作(快速入口:http://www.faviconico.org/) 3.将生成的ico图标复制到tomcat的webapps下的ROOT项目 ...

  6. js实现shell排序

    //shell排序配插入排序function shell_insert_sort(arr){ var gap = arr.length; do{ gap = parseInt(gap/3) + 1; ...

  7. 【转】同一台机器部署两个jboss方法

    更改jboss的端口信息 1) 更改webservic的端口信息D:\jboss-new\server\default\conf\jboss-service.xml文件 <mbean code= ...

  8. 兼容性调试-- 在谷歌浏览器中,td 设置colspan的失效的问题

    通过设置table width="100%"table-layout="fixed" 解决

  9. MyFragment

    手机横竖屏自动切换不同的View: Landscape-Horizontal-横屏 Portrait-Vertical-竖屏 package com.example.shad_fnst.myfragm ...

  10. Part 57 to 58 Why should you override ToString and Equal Method

    Part 57 Why should you override ToString Method sometimes you can override ToString method like that ...