luogu#P7798. [COCI 2015/2016 #6] PUTOVANJE
[COCI 2015/2016 #6] PUTOVANJE
Problem Description
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 .
Now there is a path in the forest. Along the path, there are fruits planted in order, and each fruit has a fullness value . may choose to start from any fruit position and move forward toward the -th fruit. While moving, if eating the fruit at the current position would not make the total fullness exceed , then he will definitely eat that fruit. Otherwise, he will skip that fruit and continue moving.
What is the maximum number of fruits that can eat?
Input Format
The first line contains two integers and .
The second line contains integers , the fullness value of the -th fruit.
Output Format
Output one integer, the maximum number of fruits that 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 decides to start eating from the -st fruit, then he can eat the -st, -nd, and -th fruits, for a total of fruits. If he starts from the -nd fruit, then he can eat the -nd, -rd, -th, and -th fruits, for a total of fruits.
[Constraints]
For of the testdata, , , .
[Source]
Translated from COCI 2015-2016 CONTEST #6 T2 PUTOVANJE.
The score settings follow the original COCI problem, with a full score of .
Translated by ChatGPT 5