#include <bits/stdc++.h>
using namespace std;
int main() {
int n, num, d;
cin >> n >> d;
map<int, int> blub, fred;
blub[-d] = fred[-d] = 0;
for (int i = 0; i < n; i++) {
cin >> num;
blub[num] = prev(blub.lower_bound(num))->second + 1;
fred[num] = max(fred[num], max(prev(blub.lower_bound(num + d))->second + 1, prev(fred.lower_bound(num))->second + 1));
auto it = blub.find(num);
int val = it->second;
auto nextit = next(it);
while(nextit != blub.end() && nextit->second < val) {
blub.erase(nextit);
nextit = next(blub.find(num));
}
{
auto it = fred.find(num);
int val = it->second;
auto nextit = next(it);
while(nextit != fred.end() && nextit->second < val) {
fred.erase(nextit);
nextit = next(fred.find(num));
}
}
}
cout << fred.rbegin()->second << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Incorrect |
0 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 |
296 KB |
Output is correct |
3 |
Incorrect |
0 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 |
296 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
448 KB |
Output is correct |
2 |
Correct |
321 ms |
536 KB |
Output is correct |
3 |
Correct |
300 ms |
348 KB |
Output is correct |
4 |
Correct |
299 ms |
420 KB |
Output is correct |
5 |
Correct |
235 ms |
9668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
344 KB |
Output is correct |
2 |
Correct |
143 ms |
312 KB |
Output is correct |
3 |
Correct |
290 ms |
304 KB |
Output is correct |
4 |
Correct |
149 ms |
4872 KB |
Output is correct |
5 |
Correct |
151 ms |
5060 KB |
Output is correct |
6 |
Correct |
314 ms |
13564 KB |
Output is correct |
7 |
Correct |
317 ms |
9152 KB |
Output is correct |
8 |
Correct |
137 ms |
3632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |