Company: JPMC_21july
Difficulty: hard
Maximum Barbell Weight An athlete is loading a barbell. The bar snaps if the plates on it weigh more than maxCapacity , so the athlete has to choose carefully. There are n plates available and the i -th of them weighs weights[i] . The athlete may load any subset of the plates - each plate exists only once, so it is either on the bar or in the rack. Loading nothing at all is allowed and gives a total of 0 . Report the largest total weight the athlete can put on the bar without exceeding maxCapacity . Input Format The input describes a single test case; there is no leading count of test cases. The first line contains two integers n and maxCapacity - the number of plates and the capacity of the barbell. The second line contains n space-separated integers weights[0], weights[1], ..., weights[n-1] . Output Format Print a single integer - the maximum total weight that can be loaded without exceeding maxCapacity . Constraints 1 <= n <= 42 1 <= weights[i] <= 10^9 1 <= maxCapacit