Submission #959794

#TimeUsernameProblemLanguageResultExecution timeMemory
959794happy_nodeJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
88 ms12492 KiB
#include <bits/stdc++.h> using namespace std; const int MX=2e5+5; int N; int A[MX], B[MX], pf[MX], sf[MX], ans[MX], rev[MX]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin>>N; for(int i=1;i<=N+1;i++) cin>>A[i]; for(int i=1;i<=N;i++) cin>>B[i]; vector<int> ordA,ordB; for(int i=1;i<=N+1;i++) ordA.push_back(i); for(int i=1;i<=N;i++) ordB.push_back(i); sort(ordA.begin(),ordA.end(),[&](int i, int j){ return A[i]<A[j]; }); sort(ordB.begin(),ordB.end(),[&](int i, int j){ return B[i]<B[j]; }); for(int i=1;i<=N;i++) { int x=ordA[i-1],y=ordB[i-1]; pf[i]=max(pf[i-1],max(0,A[x]-B[y])); } for(int i=N+1;i>1;i--) { int x=ordA[i-1],y=ordB[i-2]; sf[i]=max(sf[i+1],max(0,A[x]-B[y])); } for(int i=1;i<=N+1;i++) { ans[i]=max(pf[i-1],sf[i+1]); } int p=1; for(auto x:ordA) { rev[x]=p; p++; } for(int i=1;i<=N+1;i++) { cout<<ans[rev[i]]<<" "; } cout<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...