-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22114_dp.cpp
43 lines (42 loc) · 871 Bytes
/
22114_dp.cpp
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
// 210714 #22114 ⿵ÀÌ¿Í Á¡ÇÁ Silver II
// O(N*2)
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const int MAX = 100001;
int N, K, a[MAX], d[MAX][2];
// O(N*2)
int dp(int cur, int flag) {
if (cur >= N - 1)
return 0;
int& ret = d[cur][flag];
if (ret != -1)
return ret;
ret = 0;
if (a[cur] <= K)
ret = max(ret, dp(cur + 1, flag) + 1);
else if (a[cur] > K && !flag)
ret = max(ret, dp(cur + 1, 1) + 1);
return ret;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> N >> K;
for (int i = 0; i < N - 1; i++) {
cin >> a[i];
}
memset(d, -1, sizeof(d));
int ans = 0;
// not O(N*N*2) because no memset
for (int i = 0; i < N; i++) {
ans = max(ans, dp(i, 0));
}
cout << ans + 1 << "\n";
}