B. Soldier and Badges

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/546/problem/B

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

4
1 3 1 4

Sample Output

1

HINT

题意

可以花1块钱让一个勋章加1点,然后问你要花多少钱才能使所有勋章都不一样

题解:

啊,暴力暴力

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int a[maxn];
int b[maxn];
int main()
{
int n=read();
for(int i=;i<n;i++)
{
a[i]=read();
b[a[i]]++;
}
sort(a,a+n);
int ans=;
for(int i=;i<maxn;i++)
{
if(b[i]>)
{
ans+=b[i]-;
b[i+]+=b[i]-;
b[i]=;
}
}
cout<<ans<<endl;
}

最新文章

  1. mac下配置Qt for Android+iOS
  2. GPIB:永远不会被淘汰 (转载)
  3. Ubuntu 12.04 安装MySQL
  4. 跨浏览器事件EventUtil
  5. &amp;nbsp;兼容性问题
  6. crontab读取环境变量方法
  7. wm_char
  8. php memcached缓存集群
  9. Linux显示历史记录
  10. Chipmunk僵尸物理对象的出现和解决(八)
  11. Java语言中的奇淫技巧
  12. 利用 SPICE 分析理解心电图前端中的右腿驱动
  13. hdu5358 推公式+在一个区间内的尺取+枚举法
  14. 解析eml文件
  15. Django---简单接受表单信息
  16. mysql-11元数据
  17. ubuntu中rc.local无效
  18. python 类,对象
  19. shiro简单入门介绍
  20. CodeForces - 524F And Yet Another Bracket Sequence

热门文章

  1. openjudge-NOI 2.6-2985 数字组合
  2. 9. Swarm mode
  3. html学习-css
  4. day1 str字符串常用方法
  5. lr_start_timer,lr_get_transaction_duration,lr_get_transaction_wasted_time函数使用总结
  6. 基于Redis实现——分布式锁与实现
  7. thinkphp5.0URL访问
  8. 《java虚拟机》----虚拟机字节码执行引擎
  9. POJ3292 Semi-prime H-numbers [数论,素数筛]
  10. Android中xml tool属性