#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 1e4 + 7;
int l[maxn], r[maxn], num[maxn], n;
int main()
{
while (cin >> n) {
for (int i = 0; i < n; i++) {
cin >> num[i];
}
vector<int> arr;
for (int i = 0; i < n; i++) {
l[i] = 0;
int val = num[i];
int index = lower_bound(arr.begin(), arr.end(), val) - arr.begin();
if (index >= arr.size())arr.push_back(val);
else arr[index] = val;
l[i] = index;
}
arr.clear();
for (int i = n - 1; i >= 0; i--) {
int val = num[i];
int index = lower_bound(arr.begin(), arr.end(), val) - arr.begin();
if (index >= arr.size())arr.push_back(val);
else arr[index] = val;
r[i] = index;
}
int ans = 1;
for (int i = 0; i < n; i++) {
ans = max(ans, 2 * min(l[i], r[i]) + 1);
}
cout << ans << endl;
}
return 0;
}
uva10534
最新推荐文章于 2024-11-09 20:38:27 发布