#K33967. Maximum Water Usage
Maximum Water Usage
Maximum Water Usage
You are given a number of test cases. In each test case you are provided with an integer n representing the number of watering segments, an integer w representing the maximum allowed water capacity and a list of n positive integers where each integer represents the amount of water required for that segment.
Your task is to determine the maximum total amount of water that can be used by selecting a contiguous sequence of segments so that the sum does not exceed w. Formally, given a sequence \(a_1, a_2, \dots, a_n\) and an upper bound \(w\), you need to find the maximum value of \(\sum_{i = l}^{r} a_i\) over all contiguous subsequences \(\{a_l, a_{l+1}, \dots, a_r\}\) with \(\sum_{i = l}^{r} a_i \le w\).
inputFormat
The input is given via standard input (stdin) and is formatted as follows:
- The first line contains an integer \(T\) which denotes the number of test cases.
- For each test case, the first line contains two integers \(n\) and \(w\) where \(n\) is the number of watering segments and \(w\) is the maximum water usage allowed.
- The next line contains \(n\) space-separated positive integers representing the water required for each segment.
outputFormat
For each test case, output one line containing a single integer: the maximum total amount of water usage that does not exceed \(w\).
## sample3
5 100
10 20 30 40 50
4 50
15 25 35 20
6 200
10 20 30 40 50 60
100
40
200
</p>