Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- typedef tuple<lli, int, int> tlii;
- const int N = 2e5 + 5;
- deque<tlii> snow;
- lli weight[N];
- int main(){
- int n, nDay;
- scanf("%d%d", &n, &nDay);
- lli lst = -1e18;
- for(int i = 1; i <= n; ++i){
- lli x;
- scanf("%lld", &x);
- snow.emplace_back(x - lst, i - 1, i);
- lst = x;
- }
- snow.emplace_back(1e18 - lst, n, n + 1);
- sort(snow.begin(), snow.end());
- lli l = 0;
- lli r = 0;
- lli cur = 0;
- while(nDay--){
- lli wind;
- scanf("%lld", &wind);
- cur += wind;
- l = max(l, -cur);
- r = max(r, cur);
- while(!snow.empty() && get<0>(snow.front()) <= l + r){
- lli d = get<0>(snow.front());
- int li = get<1>(snow.front());
- int ri = get<2>(snow.front());
- snow.pop_front();
- if(wind > 0){
- weight[li] += d - l;
- weight[ri] += l;
- } else {
- weight[li] += r;
- weight[ri] += d - r;
- }
- }
- }
- while(!snow.empty()){
- lli d = get<0>(snow.front());
- int li = get<1>(snow.front());
- int ri = get<2>(snow.front());
- snow.pop_front();
- weight[li] += r;
- weight[ri] += l;
- }
- for(int i = 1; i <= n; ++i){
- cout << weight[i] << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement