Codechef | Onine Coding Test | Related to Knapsack
Anonymous User
838

There are N food items lined up in a store. Given the nutritional value and weights of each of them, you need to buy a set of these food items such that they do not exceed the capacity of your carrying bag W and the overall sum of the nutritional value of the bought items is maximized. You can assume that you have enough money to buy all of these items. Also, you have 2 magic potions, using which you can increase nutrition value of any two distinct food items by certain factors. That is, given two integers X and Y, you can choose any two distinct food items and multiply their nutritional value by a factor of X and Y respectively. The magic potion does not affect the weight of the items. Now, find the maximum sum of nutritional values that you can buy, given the weight constraint.

Input : 1st line contains no. of testcase. 2nd line contains N , W, X, Y. 3 line contains weight of N items. 4 th line contains values of N items.
Output : Max nutrional value.

Example :
Input:
1
3 5 1 2
1 2 3
4 2 6

Output:
16

Comments (2)