Company: Arista
Difficulty: medium
Maximum Requirement Value Within a Balance Limit You are given N items, where each item has an associated requirement value and a balance (cost/weight) value. You are also given a total available balance W . Your goal is to select a subset of items such that the sum of the balances of the selected items does not exceed the total available balance W , while maximizing the sum of their requirement values . Each item can either be taken once or not taken at all (0/1 selection rule). The total available balance W is supplied as tot_bal . Selecting no item at all is allowed, in which case the answer is 0 . (inferred — the source never says a non-empty selection is required, and with every item heavier than tot_bal no other answer is possible) Input Format An integer N representing the number of items. An array/vector req of size N , where req[i] represents the requirement value of the i -th item. An array/vector bal of size N , where bal[i] represents the balance (cost) of the i -th item. A