variation of 0/1 knapsack but constraints are 10^19

image
This question is from TekSystem coding round 2.
I tried with normal Dp approach but got runtime error due to large constraint.

Comments (1)