Fractional Knapsack
Submissions: 4099   Accuracy:


  Difficulty: Easy   Marks: 2

Given weights and values of N items, we need to put these items in a knapsack of capacity W to get the maximum total value in the knapsack.
Note: Unlike 0/1 knapsack, you are allowed to bread the item.

First line consists of an integer T denoting the number of test cases. First line consists of two integers N and W, denoting number of items and weight respectively. Second line of every test case consists of 2*N spaced integers denoting Values and weight respectively. (Value1 Weight1 Value2 Weight2.... ValueN WeightN)

Print the maximum value possible to put items in a knapsack, upto 2 decimal place.

1 <= T <= 100
1 <= N <= 100
1 <= W <= 100


3 50
60 10 100 20 120 30
2 50
60 10 100 20


Testcase 1:
Total maximum value of item we can have is 240.00 from the given capacity of sack.


** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.