#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
2212 KB |
Output is correct |
2 |
Correct |
51 ms |
2220 KB |
Output is correct |
3 |
Correct |
52 ms |
2224 KB |
Output is correct |
4 |
Correct |
52 ms |
2232 KB |
Output is correct |
5 |
Correct |
36 ms |
3192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
13 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
1216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
320 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |