// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 2e5+5;
int n, x, a[maxn], b[maxn];
vector <int> vec;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
int j = lower_bound(all(vec), a[i]+x)-vec.begin();
b[i] = j+1;
j = lower_bound(all(vec), a[i])-vec.begin();
if (j == vec.size()) vec.pb(a[i]);
else vec[j] = a[i];
}
vec.clear();
int ans = 0;
for (int i = n-1; i >= 0; i--) {
int j = lower_bound(all(vec), -a[i])-vec.begin();
if (j == vec.size()) vec.pb(-a[i]);
else vec[j] = -a[i];
smax(ans, b[i]+j);
}
cout << ans << '\n';
return 0;
}
Compilation message
glo.cpp: In function 'int32_t main()':
glo.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if (j == vec.size()) vec.pb(a[i]);
| ~~^~~~~~~~~~~~~
glo.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if (j == vec.size()) vec.pb(-a[i]);
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
2032 KB |
Output is correct |
2 |
Correct |
40 ms |
1884 KB |
Output is correct |
3 |
Correct |
42 ms |
1884 KB |
Output is correct |
4 |
Correct |
40 ms |
1884 KB |
Output is correct |
5 |
Correct |
22 ms |
2520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
860 KB |
Output is correct |
2 |
Correct |
9 ms |
1268 KB |
Output is correct |
3 |
Correct |
9 ms |
1116 KB |
Output is correct |
4 |
Correct |
5 ms |
1376 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1356 KB |
Output is correct |
7 |
Correct |
8 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
1116 KB |
Output is correct |
2 |
Correct |
19 ms |
1116 KB |
Output is correct |
3 |
Correct |
35 ms |
2024 KB |
Output is correct |
4 |
Correct |
21 ms |
2520 KB |
Output is correct |
5 |
Correct |
11 ms |
1504 KB |
Output is correct |
6 |
Correct |
19 ms |
2260 KB |
Output is correct |
7 |
Correct |
21 ms |
2268 KB |
Output is correct |
8 |
Correct |
17 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
40 ms |
2032 KB |
Output is correct |
28 |
Correct |
40 ms |
1884 KB |
Output is correct |
29 |
Correct |
42 ms |
1884 KB |
Output is correct |
30 |
Correct |
40 ms |
1884 KB |
Output is correct |
31 |
Correct |
22 ms |
2520 KB |
Output is correct |
32 |
Correct |
9 ms |
860 KB |
Output is correct |
33 |
Correct |
9 ms |
1268 KB |
Output is correct |
34 |
Correct |
9 ms |
1116 KB |
Output is correct |
35 |
Correct |
5 ms |
1376 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
5 ms |
1356 KB |
Output is correct |
38 |
Correct |
8 ms |
1116 KB |
Output is correct |
39 |
Correct |
17 ms |
1116 KB |
Output is correct |
40 |
Correct |
19 ms |
1116 KB |
Output is correct |
41 |
Correct |
35 ms |
2024 KB |
Output is correct |
42 |
Correct |
21 ms |
2520 KB |
Output is correct |
43 |
Correct |
11 ms |
1504 KB |
Output is correct |
44 |
Correct |
19 ms |
2260 KB |
Output is correct |
45 |
Correct |
21 ms |
2268 KB |
Output is correct |
46 |
Correct |
17 ms |
1116 KB |
Output is correct |
47 |
Correct |
19 ms |
1880 KB |
Output is correct |
48 |
Correct |
19 ms |
1884 KB |
Output is correct |
49 |
Correct |
41 ms |
2276 KB |
Output is correct |
50 |
Correct |
21 ms |
3548 KB |
Output is correct |
51 |
Correct |
18 ms |
3036 KB |
Output is correct |
52 |
Correct |
23 ms |
3804 KB |
Output is correct |
53 |
Correct |
20 ms |
3744 KB |
Output is correct |
54 |
Correct |
25 ms |
4304 KB |
Output is correct |
55 |
Correct |
32 ms |
3664 KB |
Output is correct |