Another Chinese field is destined to be abused...
A and B: They are all very watery, just like a simulation;
C: CF's rare question is concise,
We can pre-process the number of ascending columns from left to right,
For example: 1 3 2 4 5 7
L [I] Starting from left 1 2 1 2 3 4
Number of descending numbers from right to left: R [I] 2 1 1 3 2 1
We found that for I: A [I-1] <A [I + 1]-1 it is possible to change a [I] to find more numbers,
Ans = max (ANS, max (L [I-1], R [I + 1]) + 1 );
There are a lot of details about hack, so be patient.
Code:
#include<iostream>#include<string>#include<string.h>#include<math.h>#include<algorithm>#include<vector>#include<set>#include<map>#define N 111111using namespace std;int a[N],l[N],r[N];int main(){ int n; cin>>n; for (int i=1;i<=n;i++){ cin>>a[i]; l[i]=r[i]=1; } int ans=1; for (int i=2;i<=n;i++) { if (a[i]>a[i-1]) l[i]+=l[i-1]; ans=max(ans,l[i]); } for (int i=n-1;i>=1;i--) if (a[i]<a[i+1]) r[i]+=r[i+1]; l[0]=-1; r[n+1]=-1; a[0]=1111111111; a[n+1]=-1; for(int i=1;i<=n;i++) { if (a[i-1]<a[i+1]-1) ans=max(ans,l[i-1]+r[i+1]+1); else ans=max(ans,max(r[i+1],l[i-1])+1); } cout<<ans<<endl; return 0;}