Submission #253719

#TimeUsernameProblemLanguageResultExecution timeMemory
253719SortingJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
116 ms10872 KiB
#include <bits/stdc++.h> using namespace std; const int k_N = 2e5 + 3; int n; pair<int, int> a[k_N]; int b[k_N]; int prefix[k_N], suffix[k_N]; int ans[k_N]; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n + 1; ++i){ cin >> a[i].first; a[i].second = i; } for(int i = 1; i <= n; ++i) cin >> b[i]; sort(a + 1, a + 1 + n + 1); sort(b + 1, b + 1 + n); for(int i = 1; i <= n; ++i) prefix[i] = max(prefix[i - 1], max(a[i].first - b[i], 0)); for(int i = n + 1; i >= 2; --i) suffix[i] = max(suffix[i + 1], max(a[i].first - b[i - 1], 0)); for(int i = 1; i <= n + 1; ++i) ans[a[i].second] = max(prefix[i - 1], suffix[i + 1]); for(int i = 1; i <= n + 1; ++i) cout << ans[i] << " "; cout << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...