# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1273790 | nthvn | Just Long Neckties (JOI20_ho_t1) | C++20 | 66 ms | 8664 KiB |
#include "bits/stdc++.h"
using namespace std;
#define LOG(n) (63 - __builtin_clzll((n)))
#define fi first
#define se second
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define ll long long
const int N = 2e5+5;
int n,a[N],b[N],pos[N];
int pre[N], suf[N], fans[N];
void precalc(){
static pii v[N];
for(int i=1;i<=n+1;i++) v[i] = {a[i], i};
sort(v+1,v+n+2);
for(int i=1;i<=n+1;i++){
pos[i] = v[i].se;
a[i] = v[i].fi;
}
sort(b+1,b+n+1);
}
signed main(){
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
if(fopen("TASK.INP", "r")){
freopen("TASK.INP", "r", stdin);
freopen("TASK.OUT", "w", stdout);
}
cin>>n;
for(int i=1;i<=n+1;i++) cin>>a[i];
for(int i=1;i<=n;i++) cin>>b[i];
precalc();
for(int i=1;i<=n;i++){
pre[i] = max(pre[i-1], a[i]-b[i]);
}
for(int i=n+1;i>=2;i--){
suf[i] = max(suf[i+1], a[i]-b[i-1]);
}
for(int i=1;i<=n+1;i++){
fans[pos[i]] = max(pre[i-1], suf[i+1]);
}
for(int i=1;i<=n+1;i++) cout<<fans[i]<<" ";
}
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... |