Submission #330290

#TimeUsernameProblemLanguageResultExecution timeMemory
330290a_playerJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
265 ms11628 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; const int nax=2e5+5; int n; pair <int,int> a[nax],b[nax]; int c[nax]; int pre[nax],succ[nax]; int main(){ cin>>n; for(int i=0;i<n+1;i++)cin>>a[i].f,a[i].s=i; for(int i=0;i<n;i++)cin>>b[i].f,b[i].s=i; sort(a,a+n+1); sort(b,b+n); pre[0]=max(0,a[0].f-b[0].f); for(int i=1;i<n;i++)pre[i]=max(pre[i-1],max(0,a[i].f-b[i].f)); succ[n-1]=max(0,a[n].f-b[n-1].f); for(int i=n-2;i>=0;i--)succ[i]=max(succ[i+1],max(0,a[i+1].f-b[i].f)); for(int i=0;i<n+1;i++){ if(i==0)c[a[i].s]=succ[i]; else if(i==n)c[a[i].s]=pre[i-1]; else c[a[i].s]=max(succ[i],pre[i-1]); } for(int i=0;i<n+1;i++)cout<<c[i]<<" "; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...