Submission #1031718

#TimeUsernameProblemLanguageResultExecution timeMemory
1031718juicyJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
76 ms10868 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 2e5 + 5; int n; int b[N], pf[N], sf[N], res[N]; array<int, 2> a[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n + 1; ++i) { cin >> a[i][0]; a[i][1] = 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) { pf[i] = max(pf[i - 1], max(0, a[i][0] - b[i])); } for (int i = n + 1; i >= 2; --i) { sf[i] = max(sf[i + 1], max(0, a[i][0] - b[i - 1])); } for (int i = 1; i <= n + 1; ++i) { res[a[i][1]] = max(pf[i - 1], sf[i + 1]); } for (int i = 1; i <= n + 1; ++i) { cout << res[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...