이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ii;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
ii A[n+1]; long long B[n];
long long ans[n+1];
for(int i = 0;i <= n;i++){
cin >> A[i].first; A[i].second = i;
}
for(int i = 0;i < n;i++) cin >> B[i];
sort(A, A + (n+1));
sort(B, B + (n));
long long pre[n];
long long suf[n];
for(int i = 0;i < n;i++){
pre[i] = max(A[i].first - B[i], 0LL);
if(i != 0) pre[i] = max(pre[i-1],pre[i]);
}
for(int i = 0;i < n;i++){
suf[i] = max(A[n-i].first - B[n-i-1], 0LL);
if(i != 0) suf[i] = max(suf[i-1],suf[i]);
}
for(int i = 0;i <= n;i++){
long long res = 0;
if(i != n) res = max(res, suf[n-i-1]);
if(i != 0) res = max(res, pre[i-1]);
ans[A[i].second] = res;
}
for(int i = 0;i <= n;i++) cout << ans[i] << " ";
}
/*
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... |