#K57377. Truck Parcel Loading

    ID: 30407 Type: Default 1000ms 256MiB

Truck Parcel Loading

Truck Parcel Loading

In this problem, you are given a series of parcels with individual weights and a truck that has a maximum weight capacity WW. The parcels are loaded one by one in the given order until adding the next parcel would cause the total weight to exceed WW. Your task is to determine how many parcels can be loaded without exceeding the weight limit.

For example, if there are 6 parcels with weights [50, 40, 60, 30, 70, 20] and the truck's capacity is 150, then the truck can load the first 3 parcels (50 + 40 + 60 = 150) exactly. The answer in this case would be 3.

Note: The parcels must be loaded in the order they are given.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains two integers mm and WW, where mm is the number of parcels and WW is the truck's weight limit.
  2. The second line contains mm space-separated integers representing the weights of the parcels in the order they must be loaded.

outputFormat

Output a single integer to standard output (stdout): the number of parcels that can be loaded before the total weight exceeds the weight limit WW.## sample

6 150
50 40 60 30 70 20
3