Hi Everyone.

I have used different approach but it runs slow.

Sort values and increase value at each iteration uptill capacity is M as per

- current max value of wt 1 or
- current max value of wt 2 - min value of wt 1 which are added added

or - none and we shall add wt 2 at next one or
- current max value of wt 2 if prev executed

Time complexity is only O(NlogN).

I have got correct answer but it runs very slow :(. It runs in 0.56 seconds. :(.

This problem was easy so upper time bound was not quite tight but I am planning to tackle harder than these. Many of you are already masters in those and thus I am confident that you can help me.

It would be immensely kind of you folks if you could give a little of our valuable time to tell me how to optimize it.

Please, any help is greatly appreciated.

Thanks for sparing some time and reading this.