#K57377. Truck Parcel Loading
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 . The parcels are loaded one by one in the given order until adding the next parcel would cause the total weight to exceed . 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:
- The first line contains two integers and , where is the number of parcels and is the truck's weight limit.
- The second line contains 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 .## sample
6 150
50 40 60 30 70 20
3