Submission #1042257

#TimeUsernameProblemLanguageResultExecution timeMemory
1042257dpsaveslivesJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
63 ms10832 KiB
#include <bits/stdc++.h> #define f first #define s second using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; cin >> N; vector<pair<int,int>> A(N+1); vector<int> ord(N+1); for(int i = 0;i<=N;++i){ cin >> A[i].f; A[i].s = i; } vector<int> B(N); for(int i = 0;i<N;++i){ cin >> B[i]; } sort(A.begin(),A.end()); sort(B.begin(),B.end()); for(int i = 0;i<=N;++i) ord[A[i].s] = i; vector<int> pref(N); for(int i = 0;i<N;++i){ if(i > 0) pref[i] = max(pref[i-1],max(A[i].f-B[i],0)); else pref[i] = max(A[i].f-B[i],0); } vector<int> suf(N); //suf[N-1] starts at the last value of B and this time also the last value of A, so i+1 for A for(int i = N-1;i>=0;--i){ if(i < N-1) suf[i] = max(suf[i+1],max(A[i+1].f-B[i],0)); else suf[i] = max(A[i+1].f-B[i],0); } for(int i = 0;i<=N;++i){ //cout << ord[i] << "\n"; if(ord[i] == 0){ cout << suf[0]; } else if(ord[i] == N){ cout << pref[N-1]; } else{ cout << max(pref[ord[i]-1],suf[ord[i]]); } //cout << "\n"; if(i != N) cout << " "; else cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...