luogu#P7798. [COCI 2015/2016 #6] PUTOVANJE

[COCI 2015/2016 #6] PUTOVANJE

Problem Description

Mislav\text{Mislav} likes spending time in the forest the most, because there are all kinds of fruits in the forest, and eating each fruit gives a certain amount of fullness. However, he will not let his total fullness exceed CC.

Now there is a path in the forest. Along the path, there are NN fruits planted in order, and each fruit has a fullness value wiw_i. Mislav\text{Mislav} may choose to start from any fruit position and move forward toward the NN-th fruit. While moving, if eating the fruit at the current position would not make the total fullness exceed CC, then he will definitely eat that fruit. Otherwise, he will skip that fruit and continue moving.

What is the maximum number of fruits that Mislav\text{Mislav} can eat?

Input Format

The first line contains two integers NN and CC.

The second line contains NN integers wiw_i, the fullness value of the ii-th fruit.

Output Format

Output one integer, the maximum number of fruits that Mislav\text{Mislav} can eat.

5 5
3 1 2 1 1
4
7 5
1 5 4 3 2 1 1
3
5 10
3 2 5 4 3
3

Hint

[Sample 1 Explanation]

If Mislav\text{Mislav} decides to start eating from the 11-st fruit, then he can eat the 11-st, 22-nd, and 44-th fruits, for a total of 33 fruits. If he starts from the 22-nd fruit, then he can eat the 22-nd, 33-rd, 44-th, and 55-th fruits, for a total of 44 fruits.

[Constraints]

For 100%100\% of the testdata, 1N10001 \le N \le 1000, 1C1061 \le C \le 10^6, 1wi10001 \le w_i \le 1000.

[Source]

Translated from COCI 2015-2016 CONTEST #6 T2 PUTOVANJE.

The score settings follow the original COCI problem, with a full score of 8080.

Translated by ChatGPT 5