Challenge: Maximum Value of the Loot

Solve the Maximizing the Value of the Loot Problem.

We'll cover the following

Problem


Maximizing the Value of the Loot Problem

Find the maximal value of items that fit into the backpack.

Input: The capacity of a backpack WW, as well as the weights (w1,,wn)(w_{1} ,\ldots,w_{n}) and costs (c1,,cn)(c_{1},\ldots, c_{n}) of nn different compounds.

Output: The maximum total value of fractions of items that fit into the backpack of the given capacity, i.e., the maximum value of c1f1++cnfnc_{1}·f_{1}+\ldots+c_{n}·f_{n} such that w1f1++wnw_{1}·f_{1}+\ldots+w_{n}·fnWf_{n} ≤ W and 0fi10 ≤ f_{i} ≤ 1 for all ii (fif_{i} is the fraction of the ii-th item taken to the backpack).

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.