Divide and conquer optimization (DP) - Codeforces