Submission #718032

#TimeUsernameProblemLanguageResultExecution timeMemory
718032niterJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
520 ms20124 KiB
#include <bits/stdc++.h> #define loop(i,a,b) for(int i=a;i<b;i++) #define pii pair<int,int> #define ff first #define ss second #define pb push_back #define ins insert #define mp make_pair using namespace std; void debug(){ cout << "\n"; } template<class T, class ...U> void debug(T a, U ...b){ cout << a << " "; debug(b...); } // 2020 A const int maxN = 200005; int main(){ int n; cin >> n; pii a[maxN]; int b[maxN]; loop(i,0,n+1){ cin >> a[i].ff; a[i].ss = i + 1; } loop(i,0,n){ cin >> b[i]; } sort(a, a + n + 1); sort(b, b + n); vector<pii> dos; multiset<pii> S; int ans[maxN] = {0}; loop(i,0,n){ S.ins( mp( max(a[i].ff - b[i], 0), a[i].ss) ); dos.pb(mp( max(a[i].ff - b[i], 0), a[i].ss )); } // for(auto &i:S){ // debug(i.ff, i.ss); // } ans[a[n].ss] = (prev(S.end()))->ff; for(int i = n-1; i >= 0; i--){ S.erase(S.find(dos[i])); S.insert( mp(max(a[i+1].ff - b[i], 0), a[i+1].ss) ); ans[a[i].ss] = (prev(S.end()))->ff; //debug("ans[", a[i].ss, "] =", ans[a[i].ss]); } loop(i,1,n+2){ cout << ans[i] << " "; } cout << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...