Submission #470547

#TimeUsernameProblemLanguageResultExecution timeMemory
470547vincent97198Just Long Neckties (JOI20_ho_t1)C++14
100 / 100
129 ms17044 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<pair<int,int>> a(n+2),b(n+1); for(int i=1;i<=n+1;++i) cin >> a[i].first; for(int i=1;i<=n;++i) cin >> b[i].first; for(int i=1;i<=n+1;++i) a[i].second=i; sort(a.begin()+1,a.end()); sort(b.begin()+1,b.end()); vector<int> Lans(n+5,-1e18),Rans(n+5,-1e18); for(int i=1;i<=n;++i){ Lans[i]=max(Lans[i-1],max(0LL,a[i].first-b[i].first)); // cout << "Lans" << Lans[i] << '\n'; } for(int i=n+1;i>=2;--i){ Rans[i]=max(Rans[i+1],max(0LL,a[i].first-b[i-1].first)); // cout << "Rans" << Rans[i] << '\n'; } vector<int> ans(n+2); for(int i=1;i<=n+1;++i){ ans[a[i].second]=max(Lans[i-1],Rans[i+1]); // cout << "a[i].second" << a[i].second << '\n'; } for(int i=1;i<=n+1;++i) cout << ans[i] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...