Submission #1036785

#TimeUsernameProblemLanguageResultExecution timeMemory
1036785andrewpJust Long Neckties (JOI20_ho_t1)C++14
100 / 100
77 ms10836 KiB
//Dedicated to my love, ivaziva #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = int64_t; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define dbg(x) cerr << #x << ": " << x << '\n'; int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); int n; cin >> n; vector<pii> a(n + 1); vector<int> b(n), ans(n + 1); for (int i = 0; i <= n; i++) { cin >> a[i].first; a[i].second = i; } sort(all(a)); for (int i = 0; i < n; i++) { cin >> b[i]; } sort(all(b)); vector<int> ss(n + 2, 0), ps(n + 2, 0); ss[n] = max(a[n].first - b[n - 1], 0); for (int i = n - 1; i >= 0; i--) { ss[i] = max(ss[i + 1], max(a[i].first - b[i - 1], 0)); } for (int i = 0; i <= n; i++) { if (i != n) { ps[i + 1] = max(ps[i], max(a[i].first - b[i], 0)); } } for (int i = 0; i <= n; i++) { ans[a[i].second] = max(ps[i], ss[i + 1]); } for (int i = 0; i <= n; i++) cout << ans[i] << ' '; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...