#P3594. [POI 2015 R3] 狼坑 Trous de loup

[POI 2015 R3] 狼坑 Trous de loup

Description

Given a sequence of length nn, you have one chance to choose a contiguous segment of length at most dd and change all numbers inside it to 00. Find the longest contiguous segment such that the sum of all numbers within this segment does not exceed pp.

Input Format

The first line contains three integers, n,p,dn, p, d.

The second line contains nn integers; the ii-th integer is wiw_i, the ii-th number in the sequence.

Output Format

Output a single integer, the length of the longest valid segment after the modification.

9 7 2
3 4 1 9 4 1 7 1 3
5

Hint

Constraints

For 100%100\% of the testdata, 1dn2×1061 \le d \le n \le 2 \times 10^6, 0p10160 \le p \le 10^{16}, 1wi1091 \leq w_i \leq 10^9.


Original title: Wilcze doły.

Translated by ChatGPT 5