Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
What I mean is if you start at i=Q[N-1], the max element, and go down, you must find the global maximum before reaching Q[N/2]. Correct me if I'm wrong.
Nice explanation ! Most elements there I managed to find too, so it kind of confirms my own conclusions. However, could you check the smaller possible optimisations ? I'd really like to have this be the fastest. I'm thinking like doing 1 ≤ i ≤ (N-1)/2, and y could be P[i]/A, which bypasses creating any subset. Thoughts ?