//In the name of GOD
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MXN = 1e6 + 10;
const ll INF = 1e18;
ll n, d, lans, ans;
ll A[MXN], B[MXN], M[MXN], Mp[MXN];
ll dp[MXN], mx[MXN], rig[MXN];
vector<ll> Num;
ll GetId(ll x){
return lower_bound(Num.begin(), Num.end(), x) - Num.begin() + 1;
}
void LIS(ll up, bool f){
dp[0] = -INF, mx[0] = lans = 0;
for(int i = 1; i <= up; i ++) dp[i] = INF;
for(int i = 1; i <= up; i ++){
if(f) rig[n - i + 1] = lower_bound(dp, dp + lans + 1, Mp[i]) - dp;
mx[i] = lower_bound(dp, dp + lans + 1, M[i]) - dp;
if(!f) ans = max(ans, mx[i] + rig[i] - 1);
lans = max(lans, mx[i]);
dp[mx[i]] = M[i];
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
cin >> n >> d;
for(int i = 1; i <= n; i ++){
cin >> A[i], B[i] = A[i] - d;
Num.push_back(A[i]);
Num.push_back(B[i]);
Num.push_back(-A[i]);
Num.push_back(-B[i]);
}
sort(Num.begin(), Num.end());
Num.resize(unique(Num.begin(), Num.end()) - Num.begin());
for(int i = 1; i <= n; i ++) M[i] = GetId(-A[n - i + 1]);
for(int i = 1; i <= n; i ++) Mp[i] = GetId(-B[n - i + 1]);
LIS(n, 1);
for(int i = 1; i <= n; i ++) M[i] = GetId(A[i]);
LIS(n, 0);
ans = max(ans, lans);
cout << ans << '\n';
return 0;
}
// NNG
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
448 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
19596 KB |
Output is correct |
2 |
Correct |
240 ms |
19584 KB |
Output is correct |
3 |
Correct |
241 ms |
19528 KB |
Output is correct |
4 |
Correct |
237 ms |
19576 KB |
Output is correct |
5 |
Correct |
104 ms |
18824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
5228 KB |
Output is correct |
2 |
Correct |
55 ms |
5224 KB |
Output is correct |
3 |
Correct |
55 ms |
5280 KB |
Output is correct |
4 |
Correct |
26 ms |
4984 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
28 ms |
5060 KB |
Output is correct |
7 |
Correct |
46 ms |
5232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
9980 KB |
Output is correct |
2 |
Correct |
118 ms |
10112 KB |
Output is correct |
3 |
Correct |
254 ms |
19576 KB |
Output is correct |
4 |
Correct |
118 ms |
18792 KB |
Output is correct |
5 |
Correct |
65 ms |
9576 KB |
Output is correct |
6 |
Correct |
124 ms |
18164 KB |
Output is correct |
7 |
Correct |
129 ms |
18696 KB |
Output is correct |
8 |
Correct |
93 ms |
9996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
448 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
243 ms |
19596 KB |
Output is correct |
28 |
Correct |
240 ms |
19584 KB |
Output is correct |
29 |
Correct |
241 ms |
19528 KB |
Output is correct |
30 |
Correct |
237 ms |
19576 KB |
Output is correct |
31 |
Correct |
104 ms |
18824 KB |
Output is correct |
32 |
Correct |
55 ms |
5228 KB |
Output is correct |
33 |
Correct |
55 ms |
5224 KB |
Output is correct |
34 |
Correct |
55 ms |
5280 KB |
Output is correct |
35 |
Correct |
26 ms |
4984 KB |
Output is correct |
36 |
Correct |
0 ms |
332 KB |
Output is correct |
37 |
Correct |
28 ms |
5060 KB |
Output is correct |
38 |
Correct |
46 ms |
5232 KB |
Output is correct |
39 |
Correct |
117 ms |
9980 KB |
Output is correct |
40 |
Correct |
118 ms |
10112 KB |
Output is correct |
41 |
Correct |
254 ms |
19576 KB |
Output is correct |
42 |
Correct |
118 ms |
18792 KB |
Output is correct |
43 |
Correct |
65 ms |
9576 KB |
Output is correct |
44 |
Correct |
124 ms |
18164 KB |
Output is correct |
45 |
Correct |
129 ms |
18696 KB |
Output is correct |
46 |
Correct |
93 ms |
9996 KB |
Output is correct |
47 |
Correct |
120 ms |
10056 KB |
Output is correct |
48 |
Correct |
119 ms |
10072 KB |
Output is correct |
49 |
Correct |
254 ms |
19652 KB |
Output is correct |
50 |
Correct |
109 ms |
18852 KB |
Output is correct |
51 |
Correct |
102 ms |
14264 KB |
Output is correct |
52 |
Correct |
134 ms |
18856 KB |
Output is correct |
53 |
Correct |
125 ms |
18952 KB |
Output is correct |
54 |
Correct |
133 ms |
19640 KB |
Output is correct |
55 |
Correct |
200 ms |
19576 KB |
Output is correct |