Kiwi Juice

Pour juice between N bottles of capacity C, each pour filling or emptying one, to maximize the sum of prices over all final amounts.

Hard8Dynamic programmingGreedyMathNo attempts yetTime limit2sMemory limit512 MB

Problem

There are NN bottles, and every bottle has the same maximum capacity of CC liters. Bottle ii holds BiB_i liters of kiwi juice.

Dotori sells this juice to buy a new laptop. The price of one bottle is set only by how much juice is in it. A price is fixed for every amount from 0 liters up to CC liters, and a fuller bottle is not always worth more. One bottle holding 0 liters can be worth more than one bottle filled to CC liters.

Instead of selling the bottles as they are, Dotori pours juice between them to push the total higher. The pouring rule is this. Pick two different bottles AA and BB, then pour from AA into BB without stopping until AA is empty or BB is full. For example, if C=10C = 10, bottle AA holds 5 liters and bottle BB holds 7 liters, then after the pour AA holds 3 liters and BB holds 10 liters. Under the same capacity, if AA holds 3 liters and BB holds 4 liters, then after the pour AA holds 0 liters and BB holds 7 liters.

Dotori may pour as many times as he wants. He is sure every bottle sells, so the money he receives is the sum of the prices of all NN bottles. Find the largest amount he can receive.

Input

The first line contains the number of bottles NN and the maximum capacity CC. (1N151 \le N \le 15, 1C491 \le C \le 49)

The second line contains B1,B2,,BNB_1, B_2, \dots, B_N, the amount of juice in each bottle. (0BiC0 \le B_i \le C)

The third line contains P0,P1,,PCP_0, P_1, \dots, P_C, the price for each amount, in order from 0 liters up to CC liters. (0Pi1060 \le P_i \le 10^6)

Output

Print the maximum amount of money Dotori can receive, on one line.