Company: Infosys sp role_26april
Difficulty: medium
You are given N items. Each item i (from 1 to N) is characterized by its weight w[i] , value v[i] , and a group label g[i] . The group label indicates special restrictions: g[i] = 0 : This item is ungrouped. You can pick any number of ungrouped items. g[i] = 1 : This item belongs to Group 1. You may pick at most one item from Group 1. g[i] = 2 : This item belongs to Group 2. You may pick at most one item from Group 2. You have a bag with a maximum total weight capacity of W . Your goal is to select a subset of items such that their total weight does not exceed W , all group restrictions are respected, and the total value of selected items is maximized. Find the maximum total value achievable. Input Format The first line contains a integer, N, denoting the number of available items. The second line contains a integer, W, denoting the maximum total weight capacity of the bag. Each of the N lines contains 3 space-separated integers, representing row i of items. Constraints 1 ≤ N ≤ 1