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 nax = 2e5+10;
int pfx[nax];
void smx(int& a, int b) { a = max(a, b); }
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x; cin >> n >> x;
vector<int> t(n);
for(int i = 0; i < n; i++) cin >> t[i];
int mx = 0;
vector<int> dp(n, INT_MAX);
for(int i = 0; i < n; i++) {
int j = (int) (lower_bound(begin(dp), end(dp), t[i])-begin(dp));
dp[j] = t[i];
pfx[i] = j+1;
smx(mx, pfx[i]);
}
dp = vector<int>(n, INT_MAX);
for(int i = n-1; i >= 0; i--) {
int pos = (int) (lower_bound(begin(dp), end(dp), -t[i]+x)-begin(dp));
smx(mx, pfx[i]+pos);
int j = (int) (lower_bound(begin(dp), end(dp), -t[i])-begin(dp));
dp[j] = -t[i];
}
cout << mx << endl;
return 0;
}
# | 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... |