Original title Link: Http://codeforces.com/problemset/problem/446/A
Test instructions: To a sequence of length n, you can modify the number of one position to find the longest continuous ascending sub-sequence.
The puzzle: When a[i+1] > a[i-1]+2, you can change the value of a[i] to make a combination of two paragraphs, and vice versa, consider A[i] as the longest on the left and the longest section on the right.
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <vector>#include <set>#include <queue>#include <map>#include <cmath>Using NamespaceStd;typedef Long LongLL;IntA[100001],Dp[100001],R[100001];IntMain(){A[0] = -1; IntN;Cin>>N; For(IntI= 1;I<=N;I++)Cin>>A[I];Dp[1] = 1; For(IntI= 2;I<=N;I++) If(A[I] >A[I-1])Dp[I] =Dp[I-1]+1; ElseDp[I] = 1;R[N] =N; For(IntI=N-1;I>= 1;I--) { If(A[I] <A[I+1])R[I] =R[I+1]; ElseR[I] =I; } IntAns= 0; For(IntI= 1;I<=N;I++) { IntSum=Dp[I-1]+1; If(A[I+1] >A[I-1]+1)Ans=Max(Ans,Sum+R[I+1]-I); Else ans = Max (ans, Max (dp[ I-1]+1 R[i+1 ]-i+1); } cout << ans < < Endl; /span>
Codeforces Round #FF (Div. 1) A. Dzy Loves Sequences