is judge data ok? i think my solution is correct as i do have a proof and i checked nlogn my solution against my bruteforce soln.
Proof?! That’s stretching it a bit.
On the other hand, here’s a test case that proves it isn’t correct, as your two solutions give different answers.
3 1 2147483647 2147483647 2147483647