#K61452. Maximum Days Accumulation Problem
Maximum Days Accumulation Problem
Maximum Days Accumulation Problem
You are given a list of integers where each integer represents a number of days, and a threshold value. Your task is to select a subset of these days such that the sum of the selected days is maximized but does not exceed the threshold.
This is a variation of the 0/1 knapsack problem. For each test case, you need to compute the maximum possible sum \( S \) such that \( S \leq T \), where \( T \) is the threshold. You can use dynamic programming techniques to solve this efficiently.
Example: For an input array [2, 3, 1, 5, 6] and threshold 10, one optimal solution selects elements that sum up to 10.
inputFormat
The first line of input contains a single integer \( Q \) representing the number of test cases. The descriptions of the test cases follow.
Each test case consists of two lines:
- The first line contains two space-separated integers \( N \) (the number of days) and \( T \) (the threshold).
- The second line contains \( N \) space-separated integers representing the list of days.
outputFormat
For each test case, output a single line containing one integer: the maximum sum of days that does not exceed the threshold.
## sample5
5 10
2 3 1 5 6
4 5
1 2 3 4
4 15
5 5 5 5
5 50
10 20 30 40 50
4 27
1 2 18 9
10
5
15
50
27
</p>