Submission
Status:
(PPPPPPPPPPPPP)(PPPPPPP)(PPPPPPPPP)
Subtask/Task Score:
{30/30}{30/30}{40/40}
Score: 100
User: august
Problemset: Red Zone
Language: cpp
Time: 0.017 second
Submitted On: 2026-03-10 20:00:56
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5+5;
int a[mx], b[mx];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n,m,len,d;
cin>> n>> m>> len>> d;
for (int i=1; i<=n; i++) cin>> a[i];
for (int i=1; i<=m; i++) cin>> b[i];
int l=1, r=m;
while (l<=r) {
int mid=(l+r)/2;
vector<int> sw(mx, 0);
for (int i=1; i<=mid; i++) sw[max(1, b[i]-len)]+=d,sw[min(n+1, b[i]+len+1)]-=d;
for (int i=1; i<mx; i++) sw[i] += sw[i-1];
bool ok=true;
for (int i=1; i<=n; i++) if (a[i] > sw[i]) {
ok=false;
break;
}
if (!ok) l=mid+1;
else r=mid-1;
}
cout<< (l==m+1 ? -1 : l);
}