Submission #1114639

#TimeUsernameProblemLanguageResultExecution timeMemory
1114639AdamGSJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
202 ms19320 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; vector<int> a(n+1); vector<int> b(n); vector<int> c(n+1); for(int i = 0;i<n+1;i++) { cin>>a[i]; c[i] = a[i]; } for(int i = 0;i<n;i++) { cin>>b[i]; } sort(a.begin(),a.end()); sort(b.begin(),b.end()); long long su[n]; su[0] = max(a[0]-b[0],0); for(int i = 1;i<n;i++) { su[i] = max(su[i-1],(long long)max(a[i]-b[i],0)); } reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); long long pr[n]; pr[0] = max(a[0] - b[0],0); for(int i = 1;i<n;i++) { pr[i] = max(pr[i-1],(long long)max(a[i]-b[i],0)); } unordered_map<int,long long> ans; ans[a[0]] = su[n-1]; for(int i = 1;i<n;i++) { ans[a[i]] = max(pr[i-1], su[n-i-1]); } ans[a[n]] = pr[n-1]; for(int i = 0;i<n+1;i++) { cout<<ans[c[i]]<<" "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...