Submission #767369

#TimeUsernameProblemLanguageResultExecution timeMemory
767369LinkedArrayJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
75 ms10732 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; int b[MAXN], cuPrimul[MAXN], cuUltimul[MAXN], ans[MAXN]; struct A{ int a, pozInit; }; A v[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, i; cin >> n; for(i = 1; i <= n + 1; i++){ cin >> v[i].a; v[i].pozInit = i; } for(i = 1; i <= n; i++){ cin >> b[i]; } sort(v, v + n + 2, [](A e1, A e2){ return (e1.a < e2.a); }); sort(b, b + n + 1); // cuPrimul[i] = oddity of party until now (this vector includes the first element but excludes the last (a[i] - b[i]) for(i = 1; i <= n + 1; i++){ cuPrimul[i] = max(cuPrimul[i - 1], max(v[i].a - b[i], 0)); // oddity of party = maximum strangeness; strangeness = max{a − b, 0} } // cuUltimul[i] = oddity of party until now (this vector excludes the first element but includes the last (a[i + 1] - b[i]) for(i = n + 1; i >= 1; i--){ cuUltimul[i] = max(cuUltimul[i + 1], max(v[i + 1].a - b[i], 0)); } for(i = 0; i <= n; i++){ ans[v[i + 1].pozInit] = max(cuPrimul[i], cuUltimul[i + 1]); } for(i = 1; i <= n + 1; i++){ cout << ans[i] << " "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...