***New Year Ratings Change***
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
题意:有n个人,每个人都有一个期望的工资数值,但这些数值有可能是相等的,如何用总和(若有多个人的期望值相同只能增加而不能减)的最小而使每个人的工资期望值加起来最小,输出最后每个人能获得的工资。
思路:使用结构体做,结构体含有两个 变量,一个是用来记录数据,一个用来记录位置,把数据按照从小到大排列,若有多个数值相等,把此数值加一,否则不变动,下移一位,操作结束之后,在按照位置排序输出即可。
在这里插入代码片
#include"iostream"
#include"cstring"
#include"algorithm"
#include"map"
using namespace std;
struct mmm
{
long long x;//记录数据
int v;//记录位置
}a[1000000];
int cmp(mmm a,mmm b)
{
return a.x<b.x;//从小到大
}
int cmp1(mmm a,mmm b)
{
return a.v<b.v;
}
int main()
{
int n;
while(cin >> n)
{
map<int,int> m;
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 2 3 3 4 5 5
for(int i= 0;i < n;i ++)
{
if(pl > a[i].x)
{
a[i].x=pl;
pl++;
}
else
{
pl=a[i].x+1;
}
}
sort(a,a+n,cmp1);
for(int i = 0;i < n;i ++)
{
cout<< a[i].x<<' ';
}
cout<<endl;
}
return 0;
}