wenbao与cf上升序列(最多改变一个变为连续严格上升序列)
http://codeforces.com/problemset/problem/446/A
1 #include <iostream> 2 using namespace std; 3 #define ll long long 4 const int maxn = 1e5+10; 5 int sum1[maxn], a[maxn], sum2[maxn]; 6 int main(){ 7 int n, ma = -1; 8 cin>>n; 9 a[n+1] = 1e9+10; 10 for(int i = 1; i <= n; i++){ 11 cin>>a[i]; 12 sum1[i] = (a[i] > a[i-1] ? sum1[i-1] + 1 : 1); 13 ma = max(ma, sum1[i]); 14 } 15 ma = min(n,ma+1); 16 for(int i = n; i>=1 ; i--){ 17 sum2[i] = (a[i] < a[i+1] ? sum2[i+1] + 1 : 1); 18 if(a[i-1] + 1 < a[i+1]) ma = max(ma, sum2[i+1]+sum1[i-1]+1); 19 } 20 cout<<ma<<endl; 21 return 0; 22 }
只有不断学习才能进步!