이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 2e5+5;
int ans[maxn];
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int N; cin >> N;
vector<pair<int,int>> a;
vector<int> b;
for (int i = 0; i < N+1; i++) {
int ai; cin >> ai;
a.push_back({ai,i});
}
for (int i = 0; i < N; i++) {
int bi; cin >> bi;
b.push_back(bi);
}
sort(a.begin(),a.end());
sort(b.begin(),b.end());
multiset<int> left, right;
for (int i = 0; i < N; i++) {
right.insert(max(0,a[i+1].first-b[i]));
}
for (int i = 0; i < N+1; i++) {
int mx = 0;
if (!left.empty()) mx = max(mx,*left.rbegin());
if (!right.empty()) mx = max(mx,*right.rbegin());
ans[a[i].second] = mx;
auto it = right.find(max(0,a[i+1].first-b[i]));
if (it != right.end()) right.erase(it);
left.insert(max(0,a[i].first-b[i]));
}
for (int i = 0; i < N+1; i++) {
cout << ans[i] << " \n"[i==N];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |