amr0's blog

By amr0, history, 4 years ago, In English

Hello Codeforces! I was trying to solve https://codeforces.net/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

  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try the testcase generated by this code:

Generator

Basically, this part of your code can lead N^2 in worst case:

Code

You should understand concept of D&C well to apply it.