#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int inf = 1e10, N = 2e5+55;
//int mod = 998244353
//int mod = 1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
void solve(){
int n, x;
cin >> n >> x;
vector<int> a(n);
for(int &i:a)cin >> i;
vector<int> lis (n+1, inf);
lis[0] = -inf;
vector<array<int,2>> at(n+1, {0, -inf});
for(int i = 0; i < n; i++){
int l = upper_bound(all(lis), a[i] - x) - lis.begin();
if (lis[l - 1] < a[i] - x) {
lis[l] = a[i] - x;
at[i + 1] = {l, a[i] - x};
}
}
int ans = at[n][0];
lis.assign(n+1, inf);
lis[0] = -inf;
for(int i = n-1; i >= 0; i--){
int l = upper_bound(all(lis), -a[i]) - lis.begin();
if(lis[l-1] < -a[i]){
lis[l] = -a[i];
}
l = lower_bound(all(lis), -at[i][1]) - lis.begin()-1;
chmax(ans, at[i][0] + l);
}
cout << ans << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
448 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
448 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
448 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
8536 KB |
Output is correct |
2 |
Correct |
42 ms |
8540 KB |
Output is correct |
3 |
Correct |
41 ms |
8536 KB |
Output is correct |
4 |
Correct |
43 ms |
8536 KB |
Output is correct |
5 |
Correct |
31 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2392 KB |
Output is correct |
2 |
Correct |
10 ms |
2392 KB |
Output is correct |
3 |
Correct |
10 ms |
2392 KB |
Output is correct |
4 |
Correct |
8 ms |
2180 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
2136 KB |
Output is correct |
7 |
Correct |
9 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
4444 KB |
Output is correct |
2 |
Correct |
20 ms |
4568 KB |
Output is correct |
3 |
Correct |
38 ms |
8540 KB |
Output is correct |
4 |
Correct |
32 ms |
7772 KB |
Output is correct |
5 |
Correct |
16 ms |
3932 KB |
Output is correct |
6 |
Correct |
27 ms |
7624 KB |
Output is correct |
7 |
Correct |
31 ms |
8024 KB |
Output is correct |
8 |
Correct |
15 ms |
4440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
448 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
50 ms |
8536 KB |
Output is correct |
28 |
Correct |
42 ms |
8540 KB |
Output is correct |
29 |
Correct |
41 ms |
8536 KB |
Output is correct |
30 |
Correct |
43 ms |
8536 KB |
Output is correct |
31 |
Correct |
31 ms |
7772 KB |
Output is correct |
32 |
Correct |
10 ms |
2392 KB |
Output is correct |
33 |
Correct |
10 ms |
2392 KB |
Output is correct |
34 |
Correct |
10 ms |
2392 KB |
Output is correct |
35 |
Correct |
8 ms |
2180 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
8 ms |
2136 KB |
Output is correct |
38 |
Correct |
9 ms |
2396 KB |
Output is correct |
39 |
Correct |
18 ms |
4444 KB |
Output is correct |
40 |
Correct |
20 ms |
4568 KB |
Output is correct |
41 |
Correct |
38 ms |
8540 KB |
Output is correct |
42 |
Correct |
32 ms |
7772 KB |
Output is correct |
43 |
Correct |
16 ms |
3932 KB |
Output is correct |
44 |
Correct |
27 ms |
7624 KB |
Output is correct |
45 |
Correct |
31 ms |
8024 KB |
Output is correct |
46 |
Correct |
15 ms |
4440 KB |
Output is correct |
47 |
Correct |
19 ms |
4444 KB |
Output is correct |
48 |
Correct |
20 ms |
4444 KB |
Output is correct |
49 |
Correct |
39 ms |
8536 KB |
Output is correct |
50 |
Correct |
34 ms |
8028 KB |
Output is correct |
51 |
Correct |
24 ms |
5976 KB |
Output is correct |
52 |
Correct |
30 ms |
7772 KB |
Output is correct |
53 |
Correct |
27 ms |
7776 KB |
Output is correct |
54 |
Correct |
29 ms |
8532 KB |
Output is correct |
55 |
Correct |
32 ms |
8528 KB |
Output is correct |