Submission #201554

#TimeUsernameProblemLanguageResultExecution timeMemory
201554kuroniJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
156 ms7148 KiB
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, a[N], b[N], pr[N], su[N], ans[N]; vector<int> ind; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n + 1; i++) { cin >> a[i]; ind.push_back(i); } for (int i = 1; i <= n; i++) { cin >> b[i]; } sort(ind.begin(), ind.end(), [](const int &u, const int &v) { return a[u] < a[v]; }); sort(a + 1, a + n + 2); sort(b + 1, b + n + 1); for (int i = 1; i <= n; i++) { pr[i] = max(pr[i - 1], a[i] - b[i]); } for (int i = n; i >= 1; i--) { su[i] = max(su[i + 1], a[i + 1] - b[i]); } for (int i = 0; i <= n; i++) { ans[ind[i]] = max(pr[i], su[i + 1]); } for (int i = 1; i <= n + 1; i++) { cout << ans[i] << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...