Submission #677012

#TimeUsernameProblemLanguageResultExecution timeMemory
677012rittin1Just Long Neckties (JOI20_ho_t1)C++17
100 / 100
264 ms24848 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; pair<int,int> a[n+2]; int b[n+1]; int ans[n+2]; for(int i=1;i<=n+1;i++){ cin >> a[i].first; a[i].second=i; } for(int i=1;i<=n;i++){ cin >> b[i]; } sort(b+1,b+n+1); sort(a+1,a+n+2); int firstdiff[n+1]; multiset<int> s; for(int i=1;i<=n;i++){ firstdiff[i]=max(0LL,a[i].first-b[i]); } int secoddiff[n+1]; for(int i=1;i<=n;i++){ secoddiff[i]=max(0LL,a[i+1].first-b[i]); s.insert(secoddiff[i]); } for(int i=1;i<=n+1;i++){ auto it=s.end(); it--; int x=*it; ans[a[i].second]=x; if(i==n+1){ break; } s.erase(s.find(secoddiff[i])); s.insert(firstdiff[i]); } 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...