NEO01 - EDITORIAL (Unofficial)

At this point, something like that will be enough… note that should be “greater negative elements should be tested first” otherwise make clear you are talking about absolute values of negative elements. Another improve, complexity is not O(n) because sorting is at least n*logn in this case. Greetings and thanks in advance…

Thanks I’ll incorporate this in the editorial, Appreciate the help !

Done the changes, thanks !

Zeros must be included into positive set… also you must check if adding some negative value to it can improve solution. For example, the case with numbers 9 and -8 has result 2 instead of 1.

Thanks @liozhou_101 @vijju123

1 Like

Yes you need to include zeroes into positive set to maximise happiness.

Yes it is the same :slight_smile:
Nice solution mate

Been testing code since 4h , no bugs ;-;

Some observation that ! ^^

Haha, i mis-read too :stuck_out_tongue:

Though I think they did use the word “SUBSET” there.

1 Like

You are only considering positive numbers in your starting subset but as I mentioned in the editorial we need to take NON-NEGATIVE numbers as our starting happiness that means you need to take 0 into consideration while building the starting subset.

Yeah… It was subset mentioned in the question

We store absolute values of negative numbers in an array and sort them, then check from lowest to highest absolute negative values whether the number can be added to out subset

https://www.codechef.com/viewsolution/14248782

here i added non-negetive number to the positive set then too WA

Subarray instead of subset amde the Q hell for me.Found out on 2nd day that i misread…wanted to bang my head on wall…and also the setters for using that type of sample I/O…

@godslayer12

Good Going

Yeah, was thinking that.
Do you have a code for this using ternary search ?

https://www.codechef.com/viewsolution/14076854