This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
glo.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |