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;
const int inf = 1e9 + 7;
int main() {
int n, x;
cin >> n >> x;
vector<int> t(n + 1);
for (int i = 1; i <= n; i ++) {
cin >> t[i];
}
vector<int> v(n, inf);
vector<int> dp(n + 1);
int r = 0;
for (int i = 1; i <= n; i ++) {
int j = lower_bound(begin(v),end(v),t[i]) - begin(v);
v[j] = t[i];
dp[i] = j + 1;
r = max(r, dp[i]);
}
v = vector<int>(n, inf);
for (int i = n; 0 < i; i --) {
int j = lower_bound(begin(v),end(v),-t[i] + x) - begin(v);
r = max(r, dp[i] + j);
j = lower_bound(begin(v),end(v),-t[i]) - begin(v);
v[j] = -t[i];
}
cout << r << '\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... |