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;
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 |
---|
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... |