NEO01 - EDITORIAL (Unofficial)

Yea almost everyone did, getting AC in one attempt is applaudible, at least for people like me. :slight_smile:

Don’t use quicksort, it has a bad worst case. Try using merge sort or the built in sort function.

use inline sort i.e.:
sort(arr,arr+n)

Quick Sort worst case goes to O(n^2) and thus exceeds time

Essentially similar kind of approach (y)

@godslayer12 i have used randomised quick sort and hence avg. time complexity is O(nlogn)

What is your question exactly ?

The time complexity should be O(nlogn) because you have to sort all the values at least.
And the greedy algorithm needs proving (though I don’t know how to prove it).

2 Likes

I don’t find anything faulty in your approach, this SHOULD definitely work.
Maybe you’re missing some corner case still testing your code for counter cases. :smiley:

What you are saying is true, don’t know the exact reason. Still it won’t hurt to try other sorting methods once. :slight_smile:

Right, in case of randomised pivot probability of running into worst case is less but not nill

I have tested it on many cases, spent hours, don’t know why it is failing. Please do inform if you find any.

Sorting will make it quite convenient to solve. Just one loop from end of array upto the -ive numbers which increases the happiness.

The real thing, in my opinion, was that to realize Q mentioned “subset” instead of “subarrays”. I just looked at sample I/O, confused subset with subarrays and banged my head on how to solve it. Lol.

3 Likes

We dont have to do much with average time. You need to make sure your WORST time complexity is meeting requirement.

Looking to improve the editorial with a demonstration of the greedy approach of adding negative elements to the initial non-negative-elements-subset … right now it just like “use it, it works”…

Okay, I appreciate the suggestion :slight_smile:
So tell me the statements you want me to add to the explanation.

This is what i was talking about :slight_smile: … very good…

2 Likes

Already done by @hikarico …

Probably you want me to explain the logic of adding negative elements ? We can add that something like “Lesser negative elements should be added first to the selected subset only then is the possibility to increase happiness”, satisfactory ?