Submission #533868

#TimeUsernameProblemLanguageResultExecution timeMemory
533868someoneSnowball (JOI21_ho_t2)C++14
100 / 100
310 ms26180 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 42, INF = 1e18; set<pair<int, int>> inter; int n, d, pos[N], dep[N], mini[N], maxi[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> d; pos[0] = -INF; pos[n+1] = INF; for(int i = 1; i <= n; i++) cin >> pos[i]; for(int i = 1; i <= d; i++) { cin >> dep[i]; dep[i] += dep[i-1]; mini[i] = min(mini[i-1], dep[i]); maxi[i] = max(maxi[i-1], dep[i]); inter.insert({maxi[i] - mini[i], i}); } for(int i = 1; i <= n; i++) { int ans = 0, pre = pos[i] - pos[i-1], aft = pos[i+1] - pos[i]; auto it = inter.lower_bound({pre, 0}); if(it == inter.end()) { ans += -mini[d]; } else { int j = (*it).second; if(dep[j-1] < dep[j]) { ans += -mini[j]; } else { ans += pre - maxi[j]; } } it = inter.lower_bound({aft, 0}); if(it == inter.end()) { ans += maxi[d]; } else { int j = (*it).second; if(dep[j-1] > dep[j]) { ans += maxi[j]; } else { ans += aft + mini[j]; } } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...