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;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int N, D;
cin >> N >> D;
typedef pair<int, int> p;
vector<p> res1, res2;
rep(i,0,N) {
int x;
cin >> x;
auto it1 = lower_bound(all(res1), p{x, 0});
if (it1 == res1.end()) res1.emplace_back(), it1 = res1.end()-1;
*it1 = {x, i};
auto it2 = lower_bound(all(res2), p{x, 0});
if (it2 == res2.end()) res2.emplace_back(), it2 = res2.end()-1;
*it2 = {x, i};
int it3 = lower_bound(all(res1), p{x+D, 0}) - res1.begin();
if (it3 == sz(res2)) res2.emplace_back(x, i);
res2[it3] = {x, i};
}
cout << max(sz(res1), sz(res2)) << endl;
}
# | 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... |