http://codeforces.com/problemset/problem/446/A
/* 贪心,开前缀后缀,枚举,每个i */ /************************************************ * Author :Powatr * Created Time :2015-8-16 20:03:03 * File Name :cf466A.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int a[MAXN]; int pre1[MAXN], pre2[MAXN]; int main(){ int n; while(~scanf("%d", &n)){ for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 1; i <= n; i++) pre1[i] = pre2[i] = 1; for(int i = 2; i <= n; i++){ if(a[i] > a[i-1]) pre1[i] = pre1[i-1] + 1; } for(int i = n - 1; i >= 1; i--){ if(a[i+1] > a[i]){ pre2[i] = pre2[i+1] + 1; } } int ans = 1; if(n > 1) ans = max(pre1[n-1] + 1, pre2[2] + 1); for(int i = 2; i <= n - 1; i++){ if(a[i+1] - a[i-1] >= 2){ ans = max(ans, pre1[i-1] + pre2[i+1] + 1); } else { ans = max(ans , pre1[i-1] + 1); ans = max(ans, pre2[i+1] + 1); } } printf("%d ", ans); } return 0; }