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>
using namespace std;
using ll = long long;
using pii = array<int, 2>;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
int main() {
cin.tie(0) -> sync_with_stdio(0);
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int &i : a) {
cin >> i;
}
vector<int> dp, pf(n);
int res = 0;
for (int i = 0; i < n; i++) {
int ind = lower_bound(all(dp), a[i]) - begin(dp);
if (ind == sz(dp)) dp.push_back(0);
dp[ind] = a[i], pf[i] = ind + 1;
res = max(res, pf[i]);
}
dp.clear();
for (int i = n - 1; i >= 0; i--) {
int ind = lower_bound(all(dp), x - a[i]) - begin(dp);
res = max(res, pf[i] + ind);
ind = lower_bound(all(dp), -a[i]) - begin(dp);
if (ind == sz(dp)) dp.push_back(0);
dp[ind] = -a[i];
}
cout << res << "\n";
}
# | 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... |