Submission #1182841

#TimeUsernameProblemLanguageResultExecution timeMemory
1182841petezaJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
60 ms7096 KiB
#include <bits/stdc++.h> using namespace std; int n, x; int cmnl[200005], cmnr[200005]; int ans[200005]; int main() { cin.tie(0) -> sync_with_stdio(0); cin >> n; vector<pair<int, int>> vec; for(int i=0;i<=n;i++) { cin >> x; vec.emplace_back(x, i); } sort(vec.begin(), vec.end()); vector<int> nother(n); for(int &e:nother) cin >> e; sort(nother.begin(), nother.end()); int cmn = 0; for(int i=0;i<=n;i++) { cmnl[i] = cmn; if(i != n) cmn = max(cmn, vec[i].first-nother[i]); } cmn = 0; for(int i=n;i>=0;i--) { cmnr[i] = cmn; if(i != 0) cmn = max(cmn, vec[i].first-nother[i-1]); } for(int i=0;i<=n;i++) { ans[vec[i].second] = max(i == 0 ? 0 : cmnl[i], i == n ? 0 : cmnr[i]); } for(int i=0;i<=n;i++) cout << ans[i] << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...