-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodechef_maxdistkt.cpp
51 lines (46 loc) · 936 Bytes
/
codechef_maxdistkt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
bool compare(pair<ll,ll> a, pair<ll,ll> b)
{
return a.second < b.second;
}
int main()
{
ll t;
cin >> t;
while(t--)
{
ll n, x;
cin >> n;
vector <pair<ll,ll>> arr;
for(int i=0; i<n; i++)
{
cin >> x;
arr.push_back(make_pair(x,i));
}
ll k=0;
sort(arr.begin(), arr.end());
for(int i=0; i<n; i++)
{
if(arr[i].first > k)
{
arr[i].first = k;
k++;
}
else if(arr[i].first == k)
{
arr[i].first = k;
}
}
sort(arr.begin(), arr.end(), compare);
for(int i=0; i<n; i++)
{
cout << arr[i].first << " ";
}
cout << "\n" ;
}
return 0;
}