#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e17 + 29;
int n, x, res;
vector<int> a;
vector<int> LIS(vector<int> a, int t){
vector<int> f(n + 5, inf); f[0] = -inf;
vector<int> dp(n, 0);
for (int i = 0; i < n; ++i){
int k = lower_bound(f.begin(), f.end(), t * a[i]) - f.begin();
dp[i] = k;
f[k] = t * a[i];
}
return dp;
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> x;
for (int i = 1; i <= n; ++i){
int t; cin >> t;
a.push_back(t);
}
vector<int> f = LIS(a, 1);
reverse(a.begin(), a.end());
vector<int> g = LIS(a, -1);
reverse(g.begin(), g.end());
int dec = 0;
for (int i = 0; i < n; ++i){
res = max(res, f[i] + dec - 1);
dec = max(g[i], dec);
}
cout << res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
8088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
2172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
4256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |