# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566740 | milisav | Just Long Neckties (JOI20_ho_t1) | C++14 | 120 ms | 11640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define maxn 500000
using namespace std;
int n;
int a[maxn];
int b[maxn];
pair<int,int> ordr[maxn];
int ans[maxn];
int pref[maxn];
int suf[maxn];
int main() {
scanf("%d",&n);
for(int i=1;i<=n+1;i++) {
scanf("%d",&a[i]);
ordr[i]={a[i],i};
}
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
sort(a+1,a+(n+2));
sort(ordr+1,ordr+(n+2));
sort(b+1,b+(n+1));
for(int i=1;i<=n;i++) pref[i]=max(pref[i-1],max(a[i]-b[i],0));
for(int i=n;i>=1;i--) suf[i]=max(suf[i+1],max(a[i+1]-b[i],0));
for(int i=1;i<=n+1;i++) {
ans[ordr[i].second] = max(pref[i-1],suf[i]);
}
for(int i=1;i<=n+1;i++) {
printf("%d ",ans[i]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |