이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
array<int, 2> a[n+1];
int b[n];
for(int i=0; i<=n; ++i) cin >> a[i][0], a[i][1] = i;
for(int &i : b) cin >> i;
sort(b, b+n);
sort(a, a+n+1);
int pre[n], suf[n+1];
pre[0] = max(a[0][0] - b[0], 0LL);
suf[n] = max(a[n][0] - b[n-1], 0LL);
for(int i=1; i<n; ++i){
pre[i] = max(pre[i-1], max(a[i][0] - b[i], 0LL));
suf[n-i] = max(suf[n-i+1], max(a[n-i][0] - b[n-i-1], 0LL));
}
int ans[n+1];
for(int i=0; i<=n; ++i){
int curr = 0;
if(i) curr = max(curr, pre[i-1]);
if(i<n) curr = max(curr, suf[i+1]);
ans[a[i][1]] = curr;
}
for(int i : ans) cout << i << ' ';
cout nl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |