제출 #791212

#제출 시각아이디문제언어결과실행 시간메모리
791212acatmeowmeowJust Long Neckties (JOI20_ho_t1)C++11
100 / 100
82 ms15552 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5; int n, arr[N + 5], b[N + 5], pos[N + 5], prefix[N + 5], suffix[N + 5], ans[N + 5]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n + 1; i++) cin >> arr[i]; for (int i = 1; i <= n; i++) cin >> b[i]; iota(pos + 1, pos + n + 2, 1); sort(pos + 1, pos + n + 2, [&](int a, int b) { return arr[a] < arr[b]; }); sort(b + 1, b + n + 1); for (int i = 1; i <= n; i++) prefix[i] = max(prefix[i - 1], max(arr[pos[i]] - b[i], 0ll)); for (int i = n; i >= 1; i--) suffix[i] = max(suffix[i + 1], max(arr[pos[i + 1]] - b[i], 0ll)); ans[n + 1] = prefix[n]; for (int i = 1; i <= n + 1; i++) ans[pos[i]] = max(prefix[i - 1], suffix[i]); for (int i = 1; i <= n + 1; i++) cout << ans[i] << " "; cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...