Good Bye 2013 C
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.
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).
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.
3
5 1 1
5 1 2
1
1000000000
1000000000
1 #pragma comment(linker,"/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <vector> 4 #include <cmath> 5 #include <stack> 6 #include <queue> 7 #include <cstring> 8 #include <iostream> 9 #include <algorithm> 10 using namespace std; 11 #define INF 0x7fffffff 12 #define mod 1000000007 13 #define ll long long 14 #define maxn 300006 15 #define pi acos(-1.0) 16 #define FF(i,n) for(int i=0;i<n;i++) 17 int n, m, s, z; 18 pair<ll,ll> a[maxn]; 19 bool cmp(pair<ll, int>a, pair<ll, int> b){ 20 return a.second < b.second; 21 } 22 int main(){ 23 scanf("%d",&n); 24 s = 0; 25 for (int i = 0; i < n; i++){ 26 scanf("%I64d", &a[i].first); 27 a[i].second = i; 28 } 29 sort(a, a + n); 30 int j=0,l,r; 31 ll m = 0, z = 0; 32 for (int i = 0; i < n; i=j){ 33 while (j<n&&a[i].first == a[j].first)j++; 34 l = i; r = j; 35 z = max(0LL, m - a[l].first + 1); 36 for (int k = l; k < r; k++){ 37 a[k].first += z; 38 z++; 39 } 40 m = a[r - 1].first; 41 } 42 sort(a, a + n, cmp); 43 for (int i = 0; i < n; i++)printf("%I64d ", a[i].first); 44 return 0; 45 }
浙公网安备 33010602011771号