New Year Ratings Change

在一个知名互联网资源站点上,管理员面临着一项新年挑战:分配独特的评级给所有用户,同时保持评级总和尽可能小。面对用户们各不相同的评级期待,如何在满足个人需求的同时优化整体分配?本文介绍了一种使用结构体进行数据排序和调整的方法,通过巧妙地处理重复值来实现最优的评级分布。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

									***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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值