#C7870. 0/1 Knapsack Problem

    ID: 51789 Type: Default 1000ms 256MiB

0/1 Knapsack Problem

0/1 Knapsack Problem

You are given a knapsack with a weight capacity \(C\) and \(N\) items. Each item has a weight and a value. Your task is to determine the maximum total value that can be put into the knapsack without exceeding its capacity. This is a classical 0/1 Knapsack Problem where each item can either be taken or left.

The input consists of multiple test cases. For each test case, you are provided the integer \(N\) (the number of items) and the integer \(C\) (the maximum capacity of the knapsack). The next two lines contain \(N\) integers each: the first list represents the weights of the items, and the second list represents the corresponding values.

Note: It is guaranteed that all input values are non-negative, and if \(N = 0\), the maximum value is \(0\).

inputFormat

The first line contains an integer \(T\) representing the number of test cases. The description of each test case follows:

  1. The first line of each test case contains two integers \(N\) and \(C\), where \(N\) is the number of items and \(C\) is the capacity of the knapsack.
  2. The second line contains \(N\) space-separated integers denoting the weights of the items.
  3. The third line contains \(N\) space-separated integers denoting the values of the items.

If \(N = 0\), the second and third lines will be empty.

outputFormat

For each test case, output a single line containing the maximum total value that can be obtained without exceeding the capacity \(C\) of the knapsack.

## sample
2
3 50
10 20 30
60 100 120
4 10
6 4 2 8
4 10 5 8
220

15

</p>