Submission #826506

#TimeUsernameProblemLanguageResultExecution timeMemory
826506dijbkrJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
353 ms27920 KiB
#include<bits/stdc++.h> typedef long long ll; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; pair<int,int>a[n+4]; int b[n+4]; for (int i=1; i<=n+1; i++) { cin >> a[i].first; a[i].second=i; } sort(a+1,a+n+1+1); // for (int i=1; i<=n+1; i++) { // cout << a[i].first << " " << a[i].second << endl; // } for (int i=1; i<=n; i++) { cin >> b[i]; } sort(b+1,b+n+1); multiset<int>s; int ans[n+4]; map<int,int>mp; for (int i=2; i<=n+1; i++) { s.insert(max(a[i].first-b[i-1],0)); mp[i]=i-1; //cout << *--s.end(); ans[a[1].second]=*--s.end(); } //cout << ans[2] << endl; //cout << *--s.end() << endl; for (int i=2; i<=n+1; i++) { int cur=max(a[i].first-b[mp[i]],0); s.erase(s.find(cur)); s.insert(max(a[i-1].first-b[mp[i]],0)); mp[i-1]=mp[i]; //cout << i << " " << a[i].second << endl; ans[a[i].second]=*--s.end(); } 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...