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;