Help! Test Cases!

My code gives WA. Any test case which break my code?


I don’t know about test cases but these kind of problems should be solved using priority queues and max heaps because we cannot guarantee whether the maximum element after every iteration

But if we sort the elements, sum of last two elements will always be greater or equal to previous element.

-1 -2 -2 -2
The answer should be -14 . Your code gives -15

1 Like

Got it thanks! My logic will be valid only for non-negative numbers.

1 Like

Yeahh :slight_smile: :slight_smile: