CodeForces 546B C(Contest #1)
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
1
5
1 2 3 2 5
2
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <list>
#include <algorithm>
#include <climits>
using namespace std;
#define lson 2*i
#define rson 2*i+1
#define LS l,mid,lson
#define RS mid+1,r,rson
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 5000005
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x)
const int mod = 1e9+7;
#define LL __int64
int n,a[3005];
int main()
{
int i,j,ans;
while(~scanf("%d",&n))
{
ans = 0;
int sum1 = 0,sum2 = 0;
for(i = 1; i<=n; i++)
{
scanf("%d",&a[i]);
sum1+=a[i];
}
sort(a+1,a+1+n);
sum2 = a[1];
for(i = 2; i<=n; i++)
{
if(a[i] == a[i-1])
a[i]++;
else if(a[i]<a[i-1])
a[i] +=(a[i-1]-a[i])+1;
sum2+=a[i];
}
printf("%d\n",sum2-sum1);
}
return 0;
}
CodeForces 546B C(Contest #1)的更多相关文章
- Codeforces 659B Qualifying Contest【模拟,读题】
写这道题题解的目的就是纪念一下半个小时才读懂题...英文一多读一读就溜号... 读题时还时要静下心来... 题目链接: http://codeforces.com/contest/659/proble ...
- 【codeforces 546B】Soldier and Badges
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- codeforces E. The Contest(最长上升子序列)
题目链接:https://codeforces.com/contest/1257/problem/E 题意:给三个序列k1,k2,k3,每个序列有一堆数,k1是前缀,k3是后缀,k2是中间,现可以从任 ...
- codeforces 659B Qualifying Contest
题目链接:http://codeforces.com/problemset/problem/659/B 题意: n个人,m个区.给出n个人的姓名(保证不相同),属于的区域,所得分数.从每个区域中选出成 ...
- 【37.74%】【codeforces 725D】Contest Balloons
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces 474B E(Contest #1)
题意: 给你一个数n,代表n段区间,接下来有n个数(a1,a2,...an)代表每段区间的长度,第一段区间为[1,a1],第二段区间为[a1+1,a1+a2],...第i段区间为[ai-1+1,ai- ...
- 第一次比赛的 C题 (好后面才补的....) CodeForces 546B
Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...
- codeforces 546B
Description Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge ...
- Codeforces April Fools Contest 2017
都是神题,我一题都不会,全程听学长题解打代码,我代码巨丑就不贴了 题解见巨神博客 假装自己没有做过这套
随机推荐
- DOM加载:浏览器渲染和操作顺序(转载 学习中。。。)
DOM加载:浏览器渲染和操作顺序 1.HTML解析完毕 2.外部脚本和样式表加载完毕 3.脚本在文档内解析并执行 4.HTML DOM完全构造起来 5.图片和外部内容加载 6.网页完成加载 基于这个顺 ...
- Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数
格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)计算代码如下: /** * 获取指定时间到格林威治时间的秒数 ...
- dshow,Sample Grabber 从摄像头采集
char* CCameraDS::QueryFrame() { long evCode, size = 0; #if CALLBACKMODE static double lastSampleTime ...
- JSON和JSONP区别和联系
由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...
- php内存处理须知【转】
04 Mar 11 深入理解PHP内存管理之谁动了我的内存 作者: Laruence( ) 本文地址: http://www.laruence.com/2011/03/04/1894.html 转 ...
- sql中out与output
--SQLQuery Create By Faywool create proc Proc_OutPutTest--创建 @numA int,--numA为存储过程的参数 @numB ...
- OpenCV图像处理中常用函数汇总(1)
//俗话说:好记性不如烂笔头 //用到opencv 中的函数时往往会一时记不起这个函数的具体参数怎么设置,故在此将常用函数做一汇总: Mat srcImage = imread("C:/Us ...
- python自定义函数大全
写的零碎的python脚本太多了,到一定阶段就会出现一个问题,即以前写过的脚本找不到了,现在临时要用,还得再重写一遍,这就非常难受了,代码不能复用. 还好我有一个比较好的习惯,我喜欢把python脚本 ...
- libsvm-3.21使用文档
Libsvm is a simple, easy-to-use, and efficient software for SVM classification and regression. (可用于分 ...
- 游戏引擎/GUI的设计与实现-序
几年前写<嵌入式GUI FTK设计与实现>,没写几篇就停止更新了.当时自己研究过MicroWindows, X Window, DirectFB, GTK+和Android的GUI,又写过 ...