Submission #202051

#TimeUsernameProblemLanguageResultExecution timeMemory
202051JustInCaseJust Long Neckties (JOI20_ho_t1)C++17
100 / 100
136 ms7036 KiB
#include <bits/stdc++.h> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int32_t n; std::cin >> n; std::vector< std::pair< int32_t, int32_t > > a(n + 1); for(int32_t i = 0; i < n + 1; i++) { std::cin >> a[i].first; a[i].second = i; } std::vector< int32_t > b(n); for(int32_t i = 0; i < n; i++) { std::cin >> b[i]; } std::sort(a.begin(), a.end()); std::sort(b.begin(), b.end()); std::vector< int32_t > prefMax(n), suffMax(n); for(int32_t i = 0; i < n; i++) { if(i != 0) { prefMax[i] = prefMax[i - 1]; } else { prefMax[i] = 0; } prefMax[i] = std::max(prefMax[i], a[i].first - b[i]); } for(int32_t i = n - 1; i >= 0; i--) { if(i != n - 1) { suffMax[i] = suffMax[i + 1]; } else { suffMax[i] = 0; } suffMax[i] = std::max(suffMax[i], a[i + 1].first - b[i]); } std::vector< int32_t > ans(n + 1); ans[a[0].second] = suffMax[0]; for(int32_t i = 1; i <= n - 1; i++) { ans[a[i].second] = std::max(prefMax[i - 1], suffMax[i]); } ans[a[n].second] = prefMax[n - 1]; for(auto &x : ans) { std::cout << x << " "; } std::cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...