#K1931. Max Calories Burned

    ID: 24624 Type: Default 1000ms 256MiB

Max Calories Burned

Max Calories Burned

You are given a calorie limit \(C\) and a set of exercises, each burning a specified amount of calories. You can perform any exercise an unlimited number of times, but the total calories burned must not exceed \(C\). Your task is to compute the maximum calories you can burn.

For each test case, you will be provided with:

  • The number of exercises \(N\).
  • The calorie limit \(C\).
  • A list of \(N\) integers representing the calories burned by each exercise.

This is an unbounded knapsack problem. The state transition is given by the formula:

[ dp[i] = \max_{\text{for each exercise } cal \le i} (dp[i - cal] + cal) ]

Your program should read from stdin and output the result for each test case to stdout.

inputFormat

The first line contains an integer \(T\), the number of test cases. For each test case, there are two lines:

  1. The first line contains two integers \(N\) and \(C\) separated by space, where \(N\) is the number of exercises and \(C\) is the calorie limit.
  2. The second line contains \(N\) integers representing the calories burned by each exercise.

outputFormat

For each test case, output a single line with the maximum calories that can be burned without exceeding the limit.

## sample
2
4 10
1 8 4 3
3 6
2 5 3
10

6

</p>