Fractional Knapsack
Mediumjavapythonccppjavascript
You have N items with values and weights and a bag of capacity W. You may take any fraction of an item. Maximise the total value carried.
Input Format
The first line contains an integer N. The second line contains N space-separated integers — the values. The third line contains N space-separated integers — the weights (all positive). The fourth line contains an integer W, the capacity.
Output Format
Print the maximum value with exactly two digits after the decimal point.
Example 1
Input
3 60 100 120 10 20 30 50
Output
240.00
Explanation: Take the first two items whole, then two-thirds of the third: 60 + 100 + 80 = 240.
- 1 <= N <= 100000
- 1 <= value[i] <= 1000000
- 1 <= weight[i] <= 1000000
- 0 <= W <= 1000000000