原题链接:http://codeforces.com/problemset/problem/546/B

原题描述:

Soldier and Badges

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.

Example

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

题目感觉很水啊,数量最多才3000个,就算3000个每个都是3000增加后的最大值也不会超过6000,所以我开了个10005的数组;先将每个读入,然后统计1-10000之间每个数字的个数,比如说3000这个数字有2个那么b[3000]值为3,然后让b[3001]增加2,b[3000]变为1,同时需要增加的总量增加2以此类推统计增加的总量即可,也不知道别人看不看得懂。。。。看看代码应该能理解

AC代码如下:

# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; int a[],b[]; int main()
{
int n,sum=;
cin>>n;
for(int i=;i<=n;i++)
{
cin>>a[i];
b[a[i]]++;
}
for(int i=;i<=;i++)
{
if(b[i]>)b[i+]+=b[i]-,sum+=b[i]-,b[i]=;
}
cout<<sum<<endl;
return ;
}

  

最新文章

  1. html5的web存储
  2. 怎样使java程序减少内存占用(转载)
  3. MFC-01-Chapter01:Hello,MFC---1.3 第一个MFC程序(01)
  4. ios 在storyboard 和 xib中,显示自定义view的预览效果
  5. [leetcode] Contains Duplicate II
  6. mysql三
  7. PHP文件下载原理
  8. react 全局面包屑
  9. Oracle之Merge用法
  10. linux系统下svn服务器操作命令
  11. jfinal获取服务器的IP和端口
  12. PHP中file_exists与is_file、is_dir的区别,以及执行效率的比较
  13. http://codeforces.com/contest/610/problem/D
  14. 【推荐】Data Structure Visualizations
  15. Elasticsearch-6.7.0系列(二)ES集群安装与验证
  16. P4782 【模板】2-SAT 问题
  17. C#多线程写日志
  18. http-server 基于nodejs的http服务器
  19. 理解JavaScript继承(三)
  20. 复习前面一个月的学习C#感觉道路好艰难啊

热门文章

  1. 决解nginx代理的django项目的admin站点无法访问,和没样式的问题。
  2. (已实践)PLSQL本地还原Oracle数据库dmp文件
  3. 联想Z485安装64位ubantu
  4. [Vim] 01 凡人操作
  5. Spring框架学习总结
  6. webpack4下url-loader打包图片问题
  7. 单词数 HDU 2072 字符串输入控制
  8. jsoncpp解析
  9. 1000行MySQL学习笔记
  10. Linux命令(持续更新)