Codeforces Round #304 (Div. 2) B. Soldier and Badges 水题

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[20];
//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=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
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("");
}
//**************************************************************************************

int a[maxn];
int b[maxn];
int main()
{
    int n=read();
    for(int i=0;i<n;i++)
    {   
        a[i]=read();
        b[a[i]]++;
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<maxn;i++)
    {
        if(b[i]>1)
        {
            ans+=b[i]-1;
            b[i+1]+=b[i]-1;
            b[i]=1;
        }
    }
    cout<<ans<<endl;
}

 

你可能感兴趣的:(codeforces)