Submission

Status:

(PPPPPPPPPPPPP)(PPPTSSS)(SSSSSSSSS)

Subtask/Task Score:

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

Score: 30

User: tHeNyXs

Problemset: Red Zone

Language: cpp

Time: 1.093 second

Submitted On: 2026-03-05 16:00:03

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int n, m, l, d;
    cin >> n >> m >> l >> d;
    vector<int> a(n+1, 0);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    int ans = -1;
    for (int i = 1; i <= m; ++i) {
        int pos; cin >> pos;
        if (ans != -1) continue;
        if (a[pos] > 0) a[pos] -= d;
        for (int j = 1; j <= l; ++j) {
            if (pos-j >= 1 && a[pos-j] > 0) a[pos-j] -= d;
            if (pos+j <= n && a[pos+j] > 0) a[pos+j] -= d;
        }
        bool flag = false;
        for (int j = 1; j <= n; ++j) {
            if (a[j] > 0) flag = true;
            if (flag) break;
        }
        if (!flag) ans = i;
    }
    cout << ans;

    return 0;
}