# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
361448 | l3nl3 | Just Long Neckties (JOI20_ho_t1) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mxsz = 2e5 + 7;
int n, a[mxsz], b[mxsz];
priority_queue<int> q;
int main () {
cin >> n;
for (int i = 1; i <= n+1; i++) {
cin >> a[i];
}
for (int j = 1; j <= n; j++) {
cin >> b[j];
}
sort(a+1, a+n+1+1);
sort(b+1, b+n+1);
reverse(b+1, b+n+1);
int r = n+1;
for (int i = 1; i <= n; i++) {
q.push(max(a[r--] - b[i], 0));
}
r = n;
for (int i = 1; i <= n+1; i++) {
cout << q.top() << ' ';
if (i != n+1) {
priority_queue<int> q_2;
bool f = 1;
while (!q.empty()) {
if (f) {
if (q.top() != a[i+1] - b[r]) {
q_2.push(q.top());
}
f = 0;
} else {
q_2.push(q.top());
}
q.pop();
}
}
q = q_2;
q.push(max(a[i] - b[r--], 0));
}
}