#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
void get(vector<int>& suff, vector<int>& suff_len, vector<int> a) {
reverse(a.begin(), a.end());
set<int> s;
for(int i = 0; i < (int) a.size(); i++) {
auto it = s.upper_bound(a[i]);
if (it == s.begin()) {
s.insert(a[i]);
}
else {
it--;
if (*it < a[i]) {
s.erase(it);
s.insert(a[i]);
}
}
suff.push_back(*s.begin());
suff_len.push_back(s.size());
// for(int j : suff) {
// cout << j << " ";
// } cout << "\n";
}
reverse(suff.begin(), suff.end());
reverse(suff_len.begin(), suff_len.end());
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> a(n);
for(int& i : a) {
cin >> i;
}
int ans = 0;
vector<int> suff, suff_len;
get(suff, suff_len, a);
for(int& i : suff) {
i += x;
}
ans = *max_element(suff_len.begin(), suff_len.end());
// suff.push_back(0);
// suff_len.push_back(0);
vector<int> dp;
for(int i = 0; i < n; i++) {
int pos = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if (pos == (int) dp.size()) {
dp.push_back(a[i]);
}
else {
dp[pos] = a[i];
}
ans = max(ans, (int) dp.size());
ans = max(ans, suff_len[i]);
if (i == n-1) continue;
auto it = lower_bound(dp.begin(), dp.end(), a[i+1]+x);
ans = max(ans, (it - dp.begin()) + suff_len[i+1]);
}
cout << ans << "\n";
// for(int i = 0; i < n; i++) {
// cout << suff[i] << " " << suff_len[i] << "\n";
// }
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
6704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
1996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
3588 KB |
Output is correct |
2 |
Correct |
38 ms |
3648 KB |
Output is correct |
3 |
Correct |
79 ms |
6764 KB |
Output is correct |
4 |
Correct |
107 ms |
11252 KB |
Output is correct |
5 |
Correct |
45 ms |
5740 KB |
Output is correct |
6 |
Correct |
68 ms |
10740 KB |
Output is correct |
7 |
Correct |
78 ms |
10772 KB |
Output is correct |
8 |
Correct |
37 ms |
3636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |