#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 4;
const int oo = 1e18;
const int mod = (1 << 9);
int t, n, q, m, k, ans = 0, a[N], dp[N], f[N]{};
vector<int>v;
void solve(){
cin >> n >> k;
for (int i = 0; i < n; i++)cin >> a[i], dp[i] = oo;
for (int i = 0; i < n; i++){
m = upper_bound(dp, dp + n, a[i]) - dp;
f[i] = m + 1;
dp[m] = a[i];
ans = max(ans, f[i]);
}
for (int i = 0; i < n; i++)dp[i] = oo;
for (int i = n - 1; i >= 0; i--){
m = lower_bound(dp, dp + n, k - a[i]) - dp;
ans = max(ans, f[i] + m);
m = upper_bound(dp, dp + n, -a[i]) - dp;
dp[m] = -a[i];
}
cout << ans;
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("prime.inp", "r", stdin); freopen("prime.out", "w", stdout);
t = 1;
//cin >> t;
while (t--)solve();
return 0;
}
Compilation message
glo.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
6660 KB |
Output is correct |
2 |
Correct |
45 ms |
7004 KB |
Output is correct |
3 |
Correct |
46 ms |
6992 KB |
Output is correct |
4 |
Correct |
44 ms |
6996 KB |
Output is correct |
5 |
Incorrect |
35 ms |
6036 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1880 KB |
Output is correct |
2 |
Correct |
10 ms |
2136 KB |
Output is correct |
3 |
Correct |
11 ms |
2140 KB |
Output is correct |
4 |
Incorrect |
9 ms |
1880 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3416 KB |
Output is correct |
2 |
Correct |
19 ms |
3420 KB |
Output is correct |
3 |
Correct |
41 ms |
6492 KB |
Output is correct |
4 |
Incorrect |
35 ms |
6224 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |