Submission #391029

#TimeUsernameProblemLanguageResultExecution timeMemory
391029lukameladzeJust Long Neckties (JOI20_ho_t1)C++14
0 / 100
2 ms332 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back using namespace std; const int N=3e5+5; long long n,idx[N],a[N],b[N],pr1[N],pr2[N],x[N],xx[N],sf1[N],sf2[N],ans[N]; int main() { cin>>n; for (int i=1; i<=n+1; i++) { cin>>a[i]; idx[a[i]]=i; //ms.insert(a[i]); } sort(a+1, a+n+2); for (int i=1; i<=n; i++) { cin>>b[i]; } sort(b+1, b+n+1); for (int i=1; i<=n; i++) { x[i]=max(0LL, a[i]-b[i]); xx[i]=max(0LL, a[i+1]-b[i]); pr1[i]=max(pr1[i-1],x[i]); pr2[i]=max(pr2[i-1],x[i]); } for (int i=n; i>=1; i--) { sf1[i]=max(x[i],sf1[i+1]);//sf1[i+1]+x[i]; sf2[i]=max(sf2[i+1],xx[i]); } // cout<<sf2[2]<<endl; for (int i=1; i<=n+1; i++) { ans[idx[a[i]]]=max(sf2[i],pr1[i-1]); } for (int i=1; i<=n+1; i++) { cout<<ans[i]<<" "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...