codeforces 546B

时间:2023-03-08 16:40:41
codeforces 546B

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

Input
41 3 1 4
Output
1
Input
51 2 3 2 5
Output
2

题意就是把所有的都弄成不一样的数,最少一共需要加几,思路就是前面一个和后面一个相同的话,后面一个就加1,贪心思想啦

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <string>
using namespace std;
#define Maxn

int A[10000];
int main()
{
	int T;
	int count = 0;
	cin >> T;
	for(int i = 0; i < T; i++)
	{
		scanf("%d",&A[i]);
	}
	sort(A,A+T);
	for(int i = 0; i < T-1; i++)
	{
		if (A[i] == A[i+1])
		{
			// count++;
			for(int j = i+1; j < T; j++)
			{
				if (A[j] == A[i])
				{
					A[j] += 1;
					count++;
				}
			}

		}
	}
	std::cout << count;
}