-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11054.cpp
More file actions
65 lines (57 loc) · 1.27 KB
/
Copy path11054.cpp
File metadata and controls
65 lines (57 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
#define MAXV 1000000
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
int main()
{
int n;
scanf("%d", &n);
vector<int> v(n + 1);
for (int i = 1; i <= n; i++)
scanf("%d", &v[i]);
vector<int> d1(n + 1);
for (int i = 1; i <= n; i++)
{
int maxv = d1[0];
for (int j = 0; j < i; j++)
{
if (v[i] > v[j] && maxv < d1[j])
maxv = d1[j];
}
d1[i] = maxv + 1;
}
vector<int> d2(n + 1);
for (int i = 1; i <= n; i++)
{
int maxv1 = d1[0];
int maxv2 = d2[0];
for (int j = 0; j < i; j++)
{
if (v[i] < v[j] && maxv1 < d1[j])
maxv1 = d1[j];
if (v[i] < v[j] && maxv2 < d2[j])
maxv2 = d2[j];
}
d2[i] = max(maxv1, maxv2) + 1;
}
printf("%d\n", *max_element(all(d2)));
return 0;
}