Submission #1227665

#TimeUsernameProblemLanguageResultExecution timeMemory
1227665wedonttalkanymoreJust Long Neckties (JOI20_ho_t1)C++20
100 / 100
64 ms11592 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pii pair <ll, ll> #define fi first #define se second const ll N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7; int n; int a[N], b[N]; ll pfs[N], suf[N], ans[N]; pii pos[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 1; i <= n + 1; i++) { cin >> a[i]; pos[i] = make_pair(a[i], i); } for (int i = 1; i <= n; i++) { cin >> b[i]; } sort(pos + 1, pos + n + 2); sort(b + 1, b + n + 1); for (int i = 1; i <= n; i++) { pfs[i] = max(pfs[i - 1], max(pos[i].fi - b[i], 0LL)); } for (int i = n; i >= 1; i--) { suf[i] = max(suf[i + 1], max(pos[i + 1].fi - b[i], 0LL)); } for (int i = 1; i <= n + 1; i++) { ans[pos[i].se] = max(pfs[i - 1], suf[i]); } for (int 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...