Submission #783295

#TimeUsernameProblemLanguageResultExecution timeMemory
783295borisAngelovJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
81 ms10732 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n; pair<int, int> a[maxn]; int b[maxn]; int answer[maxn]; int preffix[maxn]; int suffix[maxn]; void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); 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 + n + 2); sort(b + 1, b + n + 1); for (int i = 1; i <= n; ++i) { preffix[i] = max(preffix[i - 1], max(0, a[i].first - b[i])); } for (int i = n; i >= 1; --i) { suffix[i] = max(suffix[i + 1], max(0, a[i + 1].first - b[i])); } for (int i = 1; i <= n + 1; ++i) { answer[a[i].second] = max(preffix[i - 1], suffix[i]); } for (int i = 1; i <= n + 1; ++i) { cout << answer[i] << ' '; } cout << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...