-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathF1.cpp
More file actions
39 lines (37 loc) · 981 Bytes
/
F1.cpp
File metadata and controls
39 lines (37 loc) · 981 Bytes
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
#include "bits/stdc++.h"
using namespace std;
signed main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
map<int, int> cnt;
pair<int, int> a[n];
bool ok = true;
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
cnt[a[i].first] += 1;
if (cnt[a[i].first] > n / 2) {
ok = false;
}
}
sort(a, a + n);
int mx = 0;
for (auto i: cnt) mx = max(mx, i.second);
deque<int> dq(n);
for (int i = 0; i < n; i++)
dq[i] = a[i].first;
for (int i = 0; i < mx; i++) {
dq.push_front(dq.back());
dq.pop_back();
}
for (int i = 0; i < n; i++) {
a[a[i].second].first = dq[i];
}
for (int i = 0; i < n; i++)
cout << a[i].first << ' ';
cout << '\n';
}
}