Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 977F Consecutive Subsequence - Problem Statement

Large values, same pattern

As the next DP problem from Codeforces, solve "Consecutive Subsequence". This problem shows how the same four-step DP pattern works even when the values in the array are large.

You are given a sequence a1,a2,,ana_1, a_2, \dots, a_n. find a subsequence (delete some elements, but you must keep the order) such that consecutive elements in the subsequence differ by exactly one. for indices of any subsequence i1,i2,,iki_1, i_2, \dots , i_k you want aij+1=aij+1a_{i_{j+1}} = a_{i_j} + 1 Every jj.

Among all such subsequences, you want the one with maximum length. You have to output the maximum length and the indices of the subsequence with the maximum length.

Constraints: 1n21051 \le n \le 2 \cdot 10^5 1a[i]1091 \le a[i] \le 10^9