// ~Be name khoda~ //
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define cl clear
#define endll '\n'
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e9;
ll dp[maxn5], a[maxn5];
int lastof[maxn5];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n, x; cin >> n >> x;
fill(dp, dp + n + 10, inf);
int ans = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
int p = lower_bound(dp + 1, dp + n + 5, a[i]) - dp;
lastof[i] = p;
dp[p] = a[i];
ans = max(ans, p);
}
fill(dp, dp + n + 10, inf);
for(int i = n - 1; i >= 0; i--){
int p = lower_bound(dp + 1, dp + n + 5, -1 * a[i] + x) - dp;
ans = max(ans, p + lastof[i] - 1);
p = lower_bound(dp + 1, dp + n + 5, -1 * a[i]) - dp;
dp[p] = -1 * a[i];
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
6128 KB |
Output is correct |
2 |
Correct |
63 ms |
6164 KB |
Output is correct |
3 |
Correct |
55 ms |
6104 KB |
Output is correct |
4 |
Correct |
60 ms |
6164 KB |
Output is correct |
5 |
Correct |
45 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1748 KB |
Output is correct |
2 |
Correct |
14 ms |
1780 KB |
Output is correct |
3 |
Correct |
18 ms |
1748 KB |
Output is correct |
4 |
Correct |
16 ms |
1492 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
10 ms |
1612 KB |
Output is correct |
7 |
Correct |
14 ms |
1748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
3132 KB |
Output is correct |
2 |
Correct |
34 ms |
3256 KB |
Output is correct |
3 |
Correct |
56 ms |
6156 KB |
Output is correct |
4 |
Correct |
48 ms |
5408 KB |
Output is correct |
5 |
Correct |
29 ms |
2804 KB |
Output is correct |
6 |
Correct |
55 ms |
5236 KB |
Output is correct |
7 |
Correct |
44 ms |
5836 KB |
Output is correct |
8 |
Correct |
38 ms |
3268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
61 ms |
6128 KB |
Output is correct |
28 |
Correct |
63 ms |
6164 KB |
Output is correct |
29 |
Correct |
55 ms |
6104 KB |
Output is correct |
30 |
Correct |
60 ms |
6164 KB |
Output is correct |
31 |
Correct |
45 ms |
5452 KB |
Output is correct |
32 |
Correct |
15 ms |
1748 KB |
Output is correct |
33 |
Correct |
14 ms |
1780 KB |
Output is correct |
34 |
Correct |
18 ms |
1748 KB |
Output is correct |
35 |
Correct |
16 ms |
1492 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
10 ms |
1612 KB |
Output is correct |
38 |
Correct |
14 ms |
1748 KB |
Output is correct |
39 |
Correct |
40 ms |
3132 KB |
Output is correct |
40 |
Correct |
34 ms |
3256 KB |
Output is correct |
41 |
Correct |
56 ms |
6156 KB |
Output is correct |
42 |
Correct |
48 ms |
5408 KB |
Output is correct |
43 |
Correct |
29 ms |
2804 KB |
Output is correct |
44 |
Correct |
55 ms |
5236 KB |
Output is correct |
45 |
Correct |
44 ms |
5836 KB |
Output is correct |
46 |
Correct |
38 ms |
3268 KB |
Output is correct |
47 |
Correct |
30 ms |
3260 KB |
Output is correct |
48 |
Correct |
29 ms |
3204 KB |
Output is correct |
49 |
Correct |
61 ms |
6168 KB |
Output is correct |
50 |
Correct |
53 ms |
5408 KB |
Output is correct |
51 |
Correct |
35 ms |
4052 KB |
Output is correct |
52 |
Correct |
48 ms |
5456 KB |
Output is correct |
53 |
Correct |
48 ms |
5480 KB |
Output is correct |
54 |
Correct |
45 ms |
6200 KB |
Output is correct |
55 |
Correct |
55 ms |
6092 KB |
Output is correct |