Submission #319537

#TimeUsernameProblemLanguageResultExecution timeMemory
319537mariowongJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
129 ms10852 KiB
#include <bits/stdc++.h> #define x first #define y second #define pii pair<int,int> #define ll long long #define pll pair<ll,ll> #define pbb pair<bool,bool> #define mp make_pair #define pb push_back #define pf push_front #define popb pop_back #define popf pop_front #define xmod (ll)(1e9+9) #define hmod 1286031825167LL using namespace std; int n,b[200005],mxr[200005],mxl[200005],ans[200005]; pii a[200005]; int main(){ ios::sync_with_stdio(false); cin >> n; n++; for (int i=1;i<=n;i++){ cin >> a[i].x; a[i].y=i; } for (int i=1;i<n;i++){ cin >> b[i]; } sort(a+1,a+1+n); sort(b+1,b+n); for (int i=1;i<n;i++){ mxl[i]=max(mxl[i-1],a[i].x-b[i]); } for (int i=2;i<=n;i++){ mxr[i]=max(0,a[i].x-b[i-1]); } for (int i=n-1;i>=1;i--){ mxr[i]=max(mxr[i+1],mxr[i]); } for (int i=1;i<=n;i++){ ans[a[i].y]=max(mxl[i-1],mxr[i+1]); } for (int i=1;i<=n;i++){ cout << ans[i] << " "; } cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...