E - New Year Ratings Change CodeForces - 379C

One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.

There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.

The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.

Help site X cope with the challenging task of rating distribution. Find the optimal distribution.


Input

The first line contains integer n (1 ≤ n ≤ 3·105) — the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.

If there are multiple optimal solutions, print any of them.

Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000

题意,把输入的数列改成没有重复的并且总和最小。

思路,最开始想到用map,比如输入1之后就有m【1】=2,那么就能解决输入相同的数的问题,但是此做法问题在于map的指向位置有可能也会重复,比如

样例

5

1 1 2 2 3,

这样1变2之后,2就不能是2了,依次类推,可用while实现类似链表一样的去找头,但是会tle,因此换方法。

把数列排好序,用pl标记上此时的a[i]+1,那么a[i+1]如果小于pl的话,就一定是a[i+1]==a[i]了,于是把a[i+1]=pl, pl ++;即把a[i+1]变成a[i]+1;

如果大于等于Pl就不用改变a[i]了,因为肯定不会和前面的重复了,只需把pl变成比a[i]大1的数就好了。

#include"iostream"
#include"algorithm"
#include"map"
using namespace std;
typedef long long ll;
struct Point
{
	ll x;
	int v;
}a[1000005];
int cmp(Point a,Point b)
{
	return a.x<b.x;
}
int cmp2(Point a,Point b)
{
	return a.v<b.v;
}
int main()
{
	int n;
	while(cin >> n)
	{
		for(int i = 0;i < n;i ++)
		{
			cin>>a[i].x;
			a[i].v=i;
		}
		sort(a,a+n,cmp);
		int pl = a[0].x+1;
		for(int i = 1;i < n;i ++)
		{
			if(a[i].x < pl)
			{
				a[i].x=pl;
				pl++;
			}
			else
			{
				pl=a[i].x+1;
			}
		}
		sort(a,a+n,cmp2);
		for(int i = 0;i < n;i ++)
		{
			if(i)
			{
				cout<<" "<<a[i].x;
			}
			else
			{
				cout<<a[i].x;
			}
		}
		cout<<endl;
	} 
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值