Submission #369292

#TimeUsernameProblemLanguageResultExecution timeMemory
369292phathnvJust Long Neckties (JOI20_ho_t1)C++11
100 / 100
123 ms10860 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 2; int n, a[N], b[N], c[N], ind[N], l[N], r[N]; void ReadInput(){ cin >> n; for(int i = 1; i <= n + 1; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; } void Solve(){ for(int i = 1; i <= n + 1; i++) ind[i] = i; sort(ind + 1, ind + 2 + n, [](const int &x, const int &y){ return a[x] < a[y]; }); sort(b + 1, b + 1 + n); l[0] = 0; for(int i = 1; i <= n; i++) l[i] = max(l[i - 1], max(0, a[ind[i]] - b[i])); r[n + 1] = 0; for(int i = n; i >= 1; i--) r[i] = max(r[i + 1], max(0, a[ind[i + 1]] - b[i])); for(int i = 1; i <= n + 1; i++) c[ind[i]] = max(l[i - 1], r[i]); for(int i = 1; i <= n + 1; i++) cout << c[i] << ' '; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ReadInput(); Solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...