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;
void solve() {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> dp;
vector<int> longest(n);
for (int i = 0; i < n; ++i) {
auto it = lower_bound(dp.begin(), dp.end(), a[i]);
if (it == dp.end()) {
dp.push_back(a[i]);
longest[i] = dp.size();
} else {
*it = a[i];
longest[i] = it - dp.begin();
}
}
dp.clear();
int ans = 0;
for (int i = n - 1; i >= 0; --i) {
auto it = lower_bound(dp.begin(), dp.end(), -a[i] + x);
ans = max(ans, int(it - dp.begin()) + longest[i]);
it = lower_bound(dp.begin(), dp.end(), -a[i]);
if (it == dp.end()) dp.push_back(-a[i]);
else *it = -a[i];
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
# | 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... |