#K47292. Maximum Packages on Conveyor Belt
Maximum Packages on Conveyor Belt
Maximum Packages on Conveyor Belt
You are given a conveyor belt with a weight limit L and a sequence of M packages, each with a specific weight. The packages must be placed on the belt in the given order. Determine the maximum number of packages that can be placed on the conveyor belt such that the cumulative weight does not exceed L.
Mathematically, let the weights be \(w_1, w_2, \dots, w_M\) and we want to find the maximum integer \(k\) such that
[ w_1 + w_2 + \cdots + w_k \le L ]
and if \(k+1 \le M\), then
[ w_1 + w_2 + \cdots + w_k + w_{k+1} > L. ]
The input consists of multiple test cases. For each test case, compute the desired value and output the result.
inputFormat
The first line of input contains an integer T (\(1 \le T \le 1000\)) representing the number of test cases. Each test case is described in the following two lines:
- The first line of each test case contains two integers M (the number of packages) and L (the maximum weight limit of the belt).
- The second line contains M integers, where the \(i\)-th integer represents the weight of the \(i\)-th package.
outputFormat
For each test case, output a single integer on a new line representing the maximum number of packages that can be placed on the conveyor belt without exceeding the weight limit.
## sample2
5 10
1 2 3 4 5
4 15
5 5 5 5
4
3
</p>