Submission #899319

#TimeUsernameProblemLanguageResultExecution timeMemory
899319AndreySnowball (JOI21_ho_t2)C++14
100 / 100
83 ms13888 KiB
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,q,a,b; cin >> n >> q; vector<long long> haha(n); for(long long i = 0; i < n; i++) { cin >> haha[i]; } vector<pair<long long,long long>> wut(q+1); long long sm = 0,big = 0,sb = 0; for(long long i = 1; i <= q; i++) { cin >> a; sb+=a; sm = max(sm,-sb); big = max(big,sb); wut[i] = {sm,big}; } vector<long long> ans(n); for(long long i = 0; i <= n; i++) { long long br; if(i == 0 || i == n) { br = LLONG_MAX; } else { br = haha[i]-haha[i-1]; } long long l = 1,r = q; if(wut[q].first+wut[q].second < br) { a = wut[q].first; b = wut[q].second; } else { while(l < r) { long long m = (l+r)/2; if(wut[m].first+wut[m].second < br) { l = m+1; } else { r = m; } } if(wut[l].first == wut[l-1].first) { a = wut[l].first; b = br-a; } else { b = wut[l].second; a = br-b; } } if(i-1 >= 0) { ans[i-1]+=b; } if(i < n) { ans[i]+=a; } } for(long long i = 0; i < n; i++) { cout << ans[i] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...