Soldier and Badges

题目链接:https://vjudge.net/problem/CodeForces-546B

AC代码:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[3005];
    cin>>n;
    for (int i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        int total=0,t=a[0];
    for (int i=1;i<n;i++)
    {
        if (a[i]>t)
            t=a[i];
        else
        {
            total+=(t+1)-a[i];
            t++;              
        }                       
    }
    cout << total << endl;
    return 0;

 

posted @ 2017-07-24 17:06  你的女孩居居  阅读(196)  评论(0编辑  收藏  举报