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;
#ifdef LOCAL
#include "algo/debug.h"
#endif
const int inf = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> t(n);
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
vector<int> prefix_dp(n + 1, inf), prefix_lis(n);
for (int i = 0; i < n; ++i) {
int j = (int) distance(prefix_dp.begin(),
lower_bound(
prefix_dp.begin(), prefix_dp.end(),
t[i]
)
);
prefix_dp[j] = t[i];
prefix_lis[i] = j + 1;
}
vector<int> suffix_dp(n + 1, inf), suffix_lis(n);
for (int i = n - 1; i >= 0; --i) {
int j = (int) distance(suffix_dp.begin(),
lower_bound(
suffix_dp.begin(), suffix_dp.end(),
-(t[i] - x)
)
);
suffix_dp[j] = t[i];
suffix_lis[i] = j + 1;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, prefix_lis[i] + suffix_lis[i] - 1);
}
cout << ans << '\n';
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# | 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... |