# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
224022 | SomeoneUnknown | Just Long Neckties (JOI20_ho_t1) | C++14 | 165 ms | 7164 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>
using namespace std;
typedef pair<int, int> ii;
ii mii(int a, int b){
return make_pair(a,b);
}
int main(){
int n;
scanf("%d", &n);
ii nnt[n+1];
int ont[n];
for(int i = 0; i <= n; i++){
int x;
scanf("%d", &x);
nnt[i] = mii(x, i);
}
for(int i = 0; i < n; i++) scanf("%d", &ont[i]);
sort(nnt, nnt+n+1);
sort(ont, ont+n);
ii dffs[n];
for(int i = 0; i < n; i++){
dffs[i] = mii(max(nnt[i+1].first-ont[i], 0), i);
}
sort(dffs, dffs+n);
int rsidep = n-1;
int lsidemax = 0;
int ans[n+1];
//printf("%d", dffs[rsidep].first);
ans[nnt[0].second] = dffs[rsidep].first;
for(int i = 0; i < n; i++){
while(rsidep >= 0 && dffs[rsidep].second <= i){
rsidep--;
}
lsidemax = max(lsidemax, nnt[i].first-ont[i]);
ans[nnt[i+1].second] = lsidemax;
if(rsidep >= 0) ans[nnt[i+1].second] = max(dffs[rsidep].first, lsidemax);
//printf("%d %d ", dffs[rsidep].first,)
//printf("\n");
}
for(int i = 0; i <= n; i++){
printf("%d ", ans[i]);
}
}
/*
3
7 3 4 6
2 6 4
*/
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... |