-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1272D.cpp
More file actions
executable file
·42 lines (33 loc) · 834 Bytes
/
1272D.cpp
File metadata and controls
executable file
·42 lines (33 loc) · 834 Bytes
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
// Problem Code: 1272D
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int max_length(int n, vector<int>& a) {
int max_len;
vector<int> l(n, 1), r(n, 1);
// Length of increasing sequence starting at position i
for (int i = 1; i < n; i++)
if (a[i - 1] < a[i])
r[i] += r[i - 1];
// Length of increasing sequence ending at position i
for (int i = n - 2; i >= 0; i--)
if (a[i] < a[i + 1])
l[i] += l[i + 1];
// Do not remove any elements
max_len = *max_element(l.begin(), l.end());
// Remove element at position i
for (int i = 1; i < n - 1; i++)
if (a[i - 1] < a[i + 1])
max_len = max(r[i - 1] + l[i + 1], max_len);
return max_len;
}
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
cout << max_length(n, a);
return 0;
}