Wavio Sequence UVA10534


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;

const int MAXN(10010);

int arr[MAXN];
int table1[MAXN], table2[MAXN];
int ans1[MAXN], ans2[MAXN];

int find1(int l, int r, int goal, int *table)
{
	while(l < r)
	{
		int m = (l+r) >> 1;
		if(table[m] < goal)
			l = m+1;
		else
			r = m;
	}
	return l;
}

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		for(int i = 1; i <= n; ++i)
			scanf("%d", arr+i);
		int ml1 = 0, ml2 = 0;
		int ti1, ti2;
		for(int i = 1; i <= n; ++i)
		{
			ti1 = find1(1, ml1+1, arr[i], table1);
			ti2 = find1(1, ml2+1, arr[n-i+1], table2);
			ml1 = max(ti1, ml1);
			ml2 = max(ti2, ml2);
			ans1[i] = ti1;
			ans2[n-i+1] = ti2;
			table1[ti1] = arr[i];
			table2[ti2] = arr[n-i+1];
		}
		int ans = 1;
		for(int i = 1; i <= n; ++i)
			ans = max(ans, min(ans1[i], ans2[i])*2-1);
		printf("%d\n", ans);
	}
	return 0;
}


你可能感兴趣的:(Wavio Sequence UVA10534)