Final voyage

3.5

19 votes
Algorithms, Approved, Dynamic Programming, Easy, Open
Problem

"RMS Lusitania" was one of the world biggest ship of her time.On the outbreak of the First World War in 1914, she was commandeered by the Admiralty as an armed merchant cruiser. When Lusitania left New York for Liverpool on what would be her final voyage on 1 May 1915, submarine warfare was intensifying in the Atlantic. Germany had declared the seas around the United Kingdom to be a war-zone..On the afternoon of May 7, Lusitania was bombarded by a German U-Boat,few miles off the southern coast of Ireland and inside the declared “zone of war”.Lusitania was officially carrying among her cargo rifle/machine-gun ammunition, shrapnel artillery shells without powder charges and artillery fuses.Captain "Dow" of Lusitania sensed the danger before and ordered his men to save the ammunition materials as much as they can.

They had few small boats and the overall load those small boats could carry was "W".Captain "Dow" knew the value of all the "N" ammunition items.So he told his men the weight "Wi" and value "Vi" of each ammunition item.As it is too difficult to save all the ammunition,Captain then asked his men to smarty choose ammunition items such that the total weight of the ammunition is less than or equal to maximum load those small ships can afford and the corresponding total value of ammunitions saved is maximum.

INPUT:

the first line contain number of testcases "T"."T" testcases follows then.For each testcase,the first line contains the number of ammunition items "N",the second line contains the maximum load "W" those small ships can afford.The third line contains the individual weight of each ammunition item.Then the next line contains the value "V" of those "N" ammunition items.

OUTPUT:

for each testcase output the maximum value of the ammunitions that can be saved.

Constraint:

1T100

0N1000

1maximumload1000

1weightofindividualitems1000

1valueofindividualitems1000

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?