#P7798. Mislav's Fruit Feast
Mislav's Fruit Feast
Mislav's Fruit Feast
Mislav loves spending time in the forest because it is filled with a variety of fruits, each granting him a certain satiety level. However, he will never allow his total satiety to exceed ( C ).
There is a path in the forest along which ( N ) fruits are planted sequentially. Each fruit has a satiety value ( w_i ). Mislav can choose any starting position among these fruits and then move forward toward the ( N )-th fruit. As he moves, if eating the fruit at his current position does not cause his cumulative satiety to exceed ( C ) (i.e., if ( current_sum + w_i \leq C )), he must eat that fruit; otherwise, he skips it.
Determine the maximum number of fruits Mislav can eat by choosing an optimal starting position.
inputFormat
The first line contains two integers ( N ) and ( C ), separated by a space.
The second line contains ( N ) integers ( w_1, w_2, \ldots, w_N ), representing the satiety values of the fruits.
outputFormat
Output a single integer representing the maximum number of fruits that Mislav can eat.
sample
5 10
2 3 5 4 1
3