UHCC1 P3 - Busy Elevator

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type

In a magical world, pigs live under the constant threat of wolves. Thus, the pigs have developed an elevator to escape from the wolves.

One day, right before a wolf raid, there are N pigs in a queue waiting for the elevator, with the i^{\text{th}} pig having weight w_i. The elevator has a weight limit L.

Since the pigs have a bit of time before the wolf raid, at most one pig in the queue can step out and re-enter the queue at a different position.

What is the largest number of pigs that can fit onto the elevator without exceeding the weight limit?

Constraints

1\leq N\leq 10^6

0\leq L\leq 10^{18}

1\leq w_i\leq 10^9

Input Specification

The first line contains two integers N and L.

The second line of input consists of N integers w_i.

Output Specification

Output the largest number of pigs that can fit on the elevator if at most one pig changes their place.

Sample Input 1

6 11
2 4 5 2 1 6

Sample Output 1

4

Explanation for Sample Output 1

If the second pig in the queue moves to the end of the queue, then 4 pigs can enter the elevator, whose weight are 2, 5, 2, and 1, in order.

Sample Input 2

6 6
5 4 5 2 1 1

Sample Output 2

2

Sample Input 3

6 1000000000000
1 2 3 4 5 6

Sample Output 3

6

Comments

There are no comments at the moment.