#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;
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));
}
fred[num] = max(prev(blub.lower_bound(num + d))->second + 1, prev(fred.lower_bound(num))->second + 1);
{
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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
314 ms |
596 KB |
Output is correct |
2 |
Correct |
295 ms |
436 KB |
Output is correct |
3 |
Correct |
294 ms |
716 KB |
Output is correct |
4 |
Correct |
295 ms |
344 KB |
Output is correct |
5 |
Correct |
219 ms |
9592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
456 KB |
Output is correct |
2 |
Correct |
135 ms |
324 KB |
Output is correct |
3 |
Correct |
270 ms |
304 KB |
Output is correct |
4 |
Correct |
156 ms |
4924 KB |
Output is correct |
5 |
Correct |
139 ms |
4932 KB |
Output is correct |
6 |
Correct |
278 ms |
13552 KB |
Output is correct |
7 |
Correct |
302 ms |
9412 KB |
Output is correct |
8 |
Correct |
137 ms |
3396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |