/**********************GOD**********************/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <iterator>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll , ll> pll;
#define len length()
#define MP make_pair
#define fs first
#define sc second
#define pb(x) push_back(x)
#define all(x) x.begin() , x.end()
#define kill(x) cout << x , exit(0)
const ll INF = 2e9 + 8;
const ll MOD = 1e9 + 7;
const ll MXN = 2e5 + 6;
const ll LOG = 28 - 5;
int n , k , mx , ans;
int A[MXN] , B[MXN];
int dp[MXN] , pd[MXN];
void lis()
{
fill(pd , pd + MXN , INF);
pd[0] = 0;
for(int i = 1 ; i <= n ; i ++) {
int j = lower_bound(pd , pd + MXN , B[i]) - pd;
dp[n + 1 - i] = j;
pd[j] = min(pd[j] , B[i]);
}
}
void sil()
{
fill(pd , pd + MXN , INF);
pd[0] = 0;
for(int i = 1 ; i <= n ; i ++) {
int j = lower_bound(pd , pd + MXN , A[i] + k) - pd;
ans = max(ans , j + dp[i] - 1);
j = lower_bound(pd , pd + MXN , A[i]) - pd;
pd[j] = min(pd[j] , A[i]);
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 1 ; i <= n ; i ++) {
cin >> A[i];
mx = max(A[i] , mx);
}
for(int i = 1 ; i <= n ; i ++)
B[i] = (- A[n + 1 - i]) + mx + 1;
lis();
sil();
cout << ans << '\n';
return 0;
}
/*!
ahkh
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
3360 KB |
Output is correct |
2 |
Correct |
50 ms |
3412 KB |
Output is correct |
3 |
Correct |
54 ms |
3404 KB |
Output is correct |
4 |
Correct |
51 ms |
3444 KB |
Output is correct |
5 |
Correct |
36 ms |
3372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1632 KB |
Output is correct |
2 |
Correct |
13 ms |
1680 KB |
Output is correct |
3 |
Correct |
12 ms |
1664 KB |
Output is correct |
4 |
Correct |
10 ms |
1700 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
10 ms |
1632 KB |
Output is correct |
7 |
Correct |
10 ms |
1708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
2384 KB |
Output is correct |
2 |
Correct |
24 ms |
3236 KB |
Output is correct |
3 |
Correct |
48 ms |
5272 KB |
Output is correct |
4 |
Correct |
40 ms |
4592 KB |
Output is correct |
5 |
Correct |
20 ms |
2828 KB |
Output is correct |
6 |
Correct |
33 ms |
4428 KB |
Output is correct |
7 |
Correct |
39 ms |
5072 KB |
Output is correct |
8 |
Correct |
20 ms |
3136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1108 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
1 ms |
1108 KB |
Output is correct |
4 |
Correct |
1 ms |
1108 KB |
Output is correct |
5 |
Correct |
1 ms |
1108 KB |
Output is correct |
6 |
Correct |
1 ms |
1108 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
1 ms |
1108 KB |
Output is correct |
9 |
Correct |
1 ms |
1108 KB |
Output is correct |
10 |
Correct |
1 ms |
1108 KB |
Output is correct |
11 |
Correct |
1 ms |
1108 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
1108 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1108 KB |
Output is correct |
17 |
Correct |
1 ms |
1108 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
1108 KB |
Output is correct |
20 |
Correct |
1 ms |
1108 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
1108 KB |
Output is correct |
23 |
Correct |
1 ms |
1108 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1092 KB |
Output is correct |
27 |
Correct |
54 ms |
3360 KB |
Output is correct |
28 |
Correct |
50 ms |
3412 KB |
Output is correct |
29 |
Correct |
54 ms |
3404 KB |
Output is correct |
30 |
Correct |
51 ms |
3444 KB |
Output is correct |
31 |
Correct |
36 ms |
3372 KB |
Output is correct |
32 |
Correct |
12 ms |
1632 KB |
Output is correct |
33 |
Correct |
13 ms |
1680 KB |
Output is correct |
34 |
Correct |
12 ms |
1664 KB |
Output is correct |
35 |
Correct |
10 ms |
1700 KB |
Output is correct |
36 |
Correct |
1 ms |
1108 KB |
Output is correct |
37 |
Correct |
10 ms |
1632 KB |
Output is correct |
38 |
Correct |
10 ms |
1708 KB |
Output is correct |
39 |
Correct |
27 ms |
2384 KB |
Output is correct |
40 |
Correct |
24 ms |
3236 KB |
Output is correct |
41 |
Correct |
48 ms |
5272 KB |
Output is correct |
42 |
Correct |
40 ms |
4592 KB |
Output is correct |
43 |
Correct |
20 ms |
2828 KB |
Output is correct |
44 |
Correct |
33 ms |
4428 KB |
Output is correct |
45 |
Correct |
39 ms |
5072 KB |
Output is correct |
46 |
Correct |
20 ms |
3136 KB |
Output is correct |
47 |
Correct |
30 ms |
3228 KB |
Output is correct |
48 |
Correct |
26 ms |
3132 KB |
Output is correct |
49 |
Correct |
52 ms |
5340 KB |
Output is correct |
50 |
Correct |
37 ms |
4568 KB |
Output is correct |
51 |
Correct |
31 ms |
3636 KB |
Output is correct |
52 |
Correct |
40 ms |
4692 KB |
Output is correct |
53 |
Correct |
34 ms |
4620 KB |
Output is correct |
54 |
Correct |
49 ms |
5388 KB |
Output is correct |
55 |
Correct |
44 ms |
5388 KB |
Output is correct |