Submission #897840

#TimeUsernameProblemLanguageResultExecution timeMemory
897840arbuzickJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
76 ms11608 KiB
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n + 1), b(n); vector<pair<int, int>> a_s(n + 1); for (int i = 0; i < n + 1; ++i) { cin >> a[i]; a_s[i] = {a[i], i}; } for (int i = 0; i < n; ++i) { cin >> b[i]; } sort(a_s.begin(), a_s.end()); sort(b.begin(), b.end()); vector<int> ans(n + 1); vector<int> pr_ans(n + 1), suff_ans(n + 1); for (int i = 0; i < n; ++i) { pr_ans[i + 1] = max(pr_ans[i], a_s[i].first - b[i]); } for (int i = n; i > 0; --i) { suff_ans[i - 1] = max(suff_ans[i], a_s[i].first - b[i - 1]); } for (int i = 0; i < n + 1; ++i) { ans[a_s[i].second] = max(pr_ans[i], suff_ans[i]); } for (int i = 0; i < n + 1; ++i) { cout << ans[i] << ' '; } cout << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(25); cout << fixed; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...