Hello Codeforces! I was trying to solve https://codeforces.me/gym/102920/problem/L using divide and conquer. To get the solution that crosses the midpoint I use the observation that the left endpoint, at index i, will be in a monotonically increasing sequence and the right endpoint, at index j, will be in a monotonically decreasing sequence but I get TLE. This is a code snippet from the code I submitted: https://ideone.com/pRWLDD . Your help is appreciated
Try the testcase generated by this code:
Basically, this part of your code can lead N^2 in worst case:
You should understand concept of D&C well to apply it.