The Robbery

Time limit3sMemory limit128 MB

Summary
Given N item types where type k has exactly k identical copies, pick copies within a weight budget M to maximize total value (bounded knapsack with huge M and small N).
Level

Medium6 of 10

Topics
Dynamic programming, Combinatorics, Greedy
Solved
No attempts yet

Problem

In the downtown of Bucharest there is a very big bank with a very big vault. Inside the vault there are NN very big boxes, numbered from 1 to NN. Inside the box with number kk there are exactly kk very big diamonds, and every diamond in that box has weight WkW_k and cost CkC_k.

John and Brus are inside the vault at the moment. They would like to steal everything, but unfortunately they are able to carry diamonds with a total weight not exceeding MM.

You may take any number of diamonds from box kk, from 0 up to all kk of them. Your task is to help John and Brus choose diamonds with a total weight less than or equal to MM and the maximal possible total cost.

Input

The first line contains a single integer TT — the number of test cases. Each test case starts with a line containing two integers NN and MM separated by a single space. The next line contains NN integers WkW_k separated by single spaces. The following line contains NN integers CkC_k separated by single spaces.

Output

For each test case print a single line containing the maximal possible total cost of the stolen diamonds.

Constraints

  • 1≤T≤741 \le T \le 74
  • 1≤N≤151 \le N \le 15
  • 1≤M≤1091 \le M \le 10^9
  • 1≤Wk,Ck≤1091 \le W_k, C_k \le 10^9

Examples1

  1. Example 1

    Input
    2
    2 4
    3 2
    5 3
    3 100
    4 7 1
    5 9 2
    
    Expected output
    6
    29