Fractional Knapsack
The first line of input contains two space separated integers, that denote the value of N and W.
Each of the following N lines contains two space separated integers, that denote value and weight, respectively, of the N items.
1 <= N = 2*10^5
1 <= W <= 10^9
1 <= value, weight <= 10^5
Time Limit: 1 sec
Print the maximum total value upto six decimal places.
4 22
6 4
6 4
4 4
4 4
20.000000
The total weight of all the items is 16 units, which is less than the total capacity of knapsack, i.e 22 units. Hence, we will add all the items in the knapsack and total value will be 20 units.
#include<bits/stdc++.h>using namespace std;int main(){ // write your code here int n,w; cin>>n>>w; return 0;}
Comments
Post a Comment