Codeforces Round #298 (Div. 2)--D. Handshakes

时间:2021-09-06 11:55:22
#include <stdio.h>
#include <algorithm>
#include <set> using namespace std; #define forn(i, n) for (int i = 0; i < int(n); i++) typedef pair<int, int> pii;
const int N = ; int n;
set<pii> a[];
int ans[N]; int main() {
scanf("%d", &n);
forn(i, n) {
int x;
scanf("%d", &x);
a[x % ].insert(make_pair(x, i));
} int cur = ;
forn(i, n) {
set <pii> :: iterator it = a[cur % ].lower_bound(make_pair(cur, -));
pii c;
if (it != a[cur % ].end() && (*it).first == cur) {
c = *(it);
ans[i] = c.second + ;
} else {
if (it == a[cur % ].begin()) {
puts("Impossible");
return ;
} else {
it--;
c = *(it);
ans[i] = c.second + ;
}
} a[cur % ].erase(c);
cur = c.first + ;
} puts("Possible");
forn(i, n)
printf("%d ", ans[i]); return ;
}