#include <iostream>
using namespace std;
#define f first
#define s second
#define int long long
#define MAXP  3000000000000
struct fSnB{
    int w,p;
};
signed main(){
    ios::sync_with_stdio(false);cin.tie();cout.tie();
//    freopen("input.in","r",stdin);
    int N,Q; cin>>N>>Q;
    fSnB ball[N];
    pair<int,int> snow[N+1];
    for(int i=0;i<N;i++){
        cin>>ball[i].p;
        ball[i].w=0;
    }
    snow[0]={-MAXP,ball[0].p};
    for(int i=1;i<N;i++){
        snow[i]={ball[i-1].p,ball[i].p};
    }
    snow[N]={ball[N-1].p,MAXP};
    int d,v,cd,a;
    for(int q=0;q<Q;q++){
        cin>>d;
        if(d>0){
            v=N;
            for(int i=N-1;i>=0;i--){
                cd=d;
                while(ball[i].p+cd<=snow[v].f){
                    v--;
                }
                while(cd!=0 && ball[i].p<=snow[v].f){
                    if(ball[i].p+cd<snow[v].s){
                        ball[i].w+=ball[i].p+cd-snow[v].f;
                        a=ball[i].p+cd-snow[v].f;
                        snow[v].f=ball[i].p+cd;
                        cd-=a;
                    }
                    else{
                        a=ball[i].p+cd-snow[i].f;
                        ball[i].w+=snow[v].s-snow[v].f;
                        snow[v].f=snow[v].s;
                        cd-=a;
                    }
                    v--;
                }
                v++;
                ball[i].p+=d;
            }
        }
        else{
            // same code but other direction 
            v=0;
            d*=-1;
            for(int i=0;i<=N;i++){
                cd=d;
                while(ball[i].p-cd>=snow[v].s){
                    v++;
                }
                while(cd!=0 && ball[i].p>=snow[v].s){
                    if(ball[i].p-cd>snow[v].f){
                        ball[i].w+=snow[v].s-(ball[i].p-cd);
                        a=snow[v].s-(ball[i].p-cd);
                        snow[v].s=ball[i].p-cd;
                        cd-=a;
                    }//
                    else{
                        a=snow[i].s-(ball[i].p-cd);
                        ball[i].w+=snow[v].s-snow[v].f;
                        snow[v].f=snow[v].s;
                        cd-=a;
                    }
                    v++;
                }
                v--;
                ball[i].p-=d;
            }
            
        }
    }
    for(int i=0;i<N;i++){
        cout<<ball[i].w<<'\n';
    }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |