Submission #1092994

#TimeUsernameProblemLanguageResultExecution timeMemory
1092994ortsacJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
150 ms15604 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<long long, long long> #define fr first #define se second int32_t main() { //freopen("in", "r", stdin); int n; cin >> n; vector<pii> a(n + 2); vector<int> b(n + 1); for (int i = 1; i <= (n + 1); i++) { cin >> a[i].fr; a[i].se = i; } for (int i = 1; i <= n; i++) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); vector<int> pf(n + 5), sf(n + 5); for (int i = 1; i <= n; i++) { int c = max(a[i].fr - b[i], 0LL); pf[i] = max(pf[i - 1], c); } for (int i = n + 1; i >= 2; i--) { int c = max(a[i].fr - b[i - 1], 0LL); sf[i] = max(sf[i + 1], c); } vector<int> ans(n + 2); for (int i = 1; i <= (n + 1); i++) { ans[a[i].se] = max(pf[i - 1], sf[i + 1]); } for (int i = 1; i <= (n + 1); i++) cout << ans[i] << " "; cout << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...