이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, int>;
const int N = 2e5+5;
pii a[N];
long long b[N], suf[N], ans[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for(int i=0; i<n+1; i++)
{
cin >> a[i].first;
a[i].second = i;
}
for(int i=0; i<n; i++)
cin >> b[i];
sort(b, b+n);
sort(a, a+n+1);
for(int i=n; i>0; i--)
suf[i] = max(suf[i+1], a[i].first - b[i-1]);
ans[a[0].second] = suf[1];
long long now = max(a[0].first - b[0], 0LL);
for(int i=1; i<n+1; i++)
{
ans[a[i].second] = max({now, suf[i+1]});
now = max(now, a[i].first - b[i]);
}
for(int i=0; i<n+1; i++)
cout << ans[i] << " ";
cout << "\n";
}
/*
3
4 3 7 6
2 6 4
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |