Submission

Status:

(PPPPPPPPPPPPP)(PPPPPPP)(PPPPPPPPP)

Subtask/Task Score:

{30/30}{30/30}{40/40}

Score: 100

User: devilpoohs

Problemset: Red Zone

Language: cpp

Time: 0.015 second

Submitted On: 2026-03-07 10:30:01

#include<bits/stdc++.h>
using namespace std;
int n,d;
int chk(int ar[],int pl[]){
    int pls=0;
    for(int i=0;i<n;i++){
        pls+=pl[i];
        if(ar[i]-pls*d>0) return 0;
    }
    return 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int m,l;
    cin>>n>>m>>l>>d;
    int ar[n];
    int pl[n+1];
    memset(pl,0,sizeof(pl));
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    int mins[m],a;
    bool chk2=false;
    for(int i=0;i<m;i++){
        cin>>a;
        a--;
        mins[i]=a;


        
        // for(int j=s;j<=e;j++){
        //     ar[j]-=d;
        // }
        // if(chk(ar,pl) and chk2==false){
        //     cout<<i;
        //     return 0;
        // }
    }
    int lef=0,r=m;
    while(lef<r){
        
        // cout<<lef<<','<<r<<'\n';
        int mid=(lef+r)/2;
        memset(pl,0,sizeof(pl));
        for(int i=0;i<=mid;i++){
            a=mins[i];
            int s=max(a-l,0),e=min(a+l,n-1);
            pl[s]++;
            pl[e+1]--;
        }
        if(chk(ar,pl)==0){
            lef=mid+1;
        }else{
            r=mid;
        }
    }
    if(lef==m)
    cout<<-1;
    else cout<<lef+1;
    return 0;
}
/*

6 8 1 4
4 7 6 2 5 3
1
3
6
1
4
6
5
3


10
1 2 3 3 5 6 10
7
*/