#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, x;
cin >> n >> x;
int t[n];
for (int i = 0; i < n; i++)
cin >> t[i];
int lis1[n + 1];
fill(lis1, lis1 + n + 1, 2e9);
lis1[0] = -1;
int len[n], val[n];
memset(len, 0, sizeof(len));
int temp = 0, temp1 = -1;
for (int i = 0; i < n; i++) {
auto it = lower_bound(lis1, lis1 + n + 1, t[i]);
*it = t[i];
/*if (temp > (int)(it - lis1))
len[i] = temp, val[i] = temp1;
else if (temp <= (int)(it - lis1))
len[i] = temp = (int)(it - lis1), val[i] = temp1 = t[i];*/
len[i] = (int)(it - lis1);
}
int lis2[n + 1];
fill(lis2, lis2 + n + 1, -2e9);
lis2[n] = 2e9;
int ans = 1;
for (int i = n - 1; i >= 0; i--) {
auto it = upper_bound(lis2, lis2 + n + 1, t[i] - x);
ans = max(ans, len[i] + n - (int)(it - lis2));
it = upper_bound(lis2, lis2 + n + 1, t[i]);
lis2[--it - lis2] = t[i];
}
cout << ans;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:20:17: warning: unused variable 'val' [-Wunused-variable]
int len[n], val[n];
^~~
glo.cpp:22:9: warning: unused variable 'temp' [-Wunused-variable]
int temp = 0, temp1 = -1;
^~~~
glo.cpp:22:19: warning: unused variable 'temp1' [-Wunused-variable]
int temp = 0, temp1 = -1;
^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
276 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
276 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
3524 KB |
Output is correct |
2 |
Correct |
78 ms |
3548 KB |
Output is correct |
3 |
Correct |
78 ms |
3448 KB |
Output is correct |
4 |
Correct |
78 ms |
3448 KB |
Output is correct |
5 |
Correct |
56 ms |
3448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1144 KB |
Output is correct |
2 |
Correct |
19 ms |
1148 KB |
Output is correct |
3 |
Correct |
19 ms |
1144 KB |
Output is correct |
4 |
Correct |
15 ms |
1144 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
16 ms |
1144 KB |
Output is correct |
7 |
Correct |
17 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1912 KB |
Output is correct |
2 |
Correct |
34 ms |
1912 KB |
Output is correct |
3 |
Correct |
69 ms |
3436 KB |
Output is correct |
4 |
Correct |
56 ms |
3448 KB |
Output is correct |
5 |
Correct |
29 ms |
1912 KB |
Output is correct |
6 |
Correct |
50 ms |
3320 KB |
Output is correct |
7 |
Correct |
56 ms |
3320 KB |
Output is correct |
8 |
Correct |
31 ms |
2060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
348 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
276 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
82 ms |
3524 KB |
Output is correct |
28 |
Correct |
78 ms |
3548 KB |
Output is correct |
29 |
Correct |
78 ms |
3448 KB |
Output is correct |
30 |
Correct |
78 ms |
3448 KB |
Output is correct |
31 |
Correct |
56 ms |
3448 KB |
Output is correct |
32 |
Correct |
19 ms |
1144 KB |
Output is correct |
33 |
Correct |
19 ms |
1148 KB |
Output is correct |
34 |
Correct |
19 ms |
1144 KB |
Output is correct |
35 |
Correct |
15 ms |
1144 KB |
Output is correct |
36 |
Correct |
2 ms |
380 KB |
Output is correct |
37 |
Correct |
16 ms |
1144 KB |
Output is correct |
38 |
Correct |
17 ms |
1144 KB |
Output is correct |
39 |
Correct |
34 ms |
1912 KB |
Output is correct |
40 |
Correct |
34 ms |
1912 KB |
Output is correct |
41 |
Correct |
69 ms |
3436 KB |
Output is correct |
42 |
Correct |
56 ms |
3448 KB |
Output is correct |
43 |
Correct |
29 ms |
1912 KB |
Output is correct |
44 |
Correct |
50 ms |
3320 KB |
Output is correct |
45 |
Correct |
56 ms |
3320 KB |
Output is correct |
46 |
Correct |
31 ms |
2060 KB |
Output is correct |
47 |
Correct |
38 ms |
2908 KB |
Output is correct |
48 |
Correct |
39 ms |
2808 KB |
Output is correct |
49 |
Correct |
78 ms |
5368 KB |
Output is correct |
50 |
Correct |
58 ms |
4600 KB |
Output is correct |
51 |
Correct |
46 ms |
3500 KB |
Output is correct |
52 |
Correct |
60 ms |
4700 KB |
Output is correct |
53 |
Correct |
54 ms |
4728 KB |
Output is correct |
54 |
Correct |
60 ms |
5624 KB |
Output is correct |
55 |
Correct |
66 ms |
5460 KB |
Output is correct |