-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1071.cpp
More file actions
33 lines (30 loc) · 755 Bytes
/
1071.cpp
File metadata and controls
33 lines (30 loc) · 755 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int N; cin >> N;
int arr[1002]; memset(arr, 0, sizeof(arr));
for (int i = 0; i < N; i++) {
int x; cin >> x;
arr[x]++;
}
int b=-2;
while(N--) {
int x = 9999;
for (int i = 1000; i >= 0; i--) {
bool found = false;
for (int j = 0; j <i;j++) found |= arr[j] > 0;
for (int j = i+2; j <=1000;j++) found |= arr[j] > 0;
if (arr[i] && (!arr[i+1] || found) && i!=b+1) x=i;
}
assert(x!=9999);
arr[b=x]--;
cout << x << ' ';
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
solve();
return 0;
}