I was trying to solve this problem https://www.codechef.com/problems/LISA. This problem is unsolved till now. I wrote this O(NlogN) solution https://paste.ubuntu.com/p/CYrckyNx4Q/ but getting WA. I tested with many random inputs (of size <=10^4 by generating random numbers). To make sure that my code gives correct result for those random inputs I wrote another DP solution https://paste.ubuntu.com/p/4hsMRZ5XkJ/ and checked if outputs were identical. It matched in all cases i tested with (If my dp solution isn’t wrong) and couldn’t find any corner case too. Can anyone please provide a test case where my code fails?