MAXAND18_ JuneLunchtime

Can anyone help me understand why ST2 fails?

My solution:

I stored the sum for each index in an array sum( so sum[0] corresponds to sum of 2^LSB for all the elements in provided array and so on for sum[1]…). Next I did a stable sort to maintain the relative ordering and now my vector of pairs v holds the sums in the decreasing order as first element and the index for that sum as second element. I loop k times and add the corresponding maximum sum bit raised to the power of 2.

See Video Editorial.

Can someone please tell why I am getting WA on subtask 2.
My code is:
Thanks in advanced!!

Try on Test Case
3 3
2 1 3

Your Output : 3
Correct output : 7

you have to take exactly k bits in your chosen X :slight_smile:

1 Like

Thanks for the help.