#include<bits/stdc++.h>
//#include<iostream>
//#include<vector>
using namespace std;
#define _ << ' ' <<
#define pb push_back
#define all(x) begin(x), end(x)
#define mp make_pair
#define f first
#define s second
#define sz(x) int((x).size())
using ll = long long;
using db = long double;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
void trad(vector<ll>a, ll x){
int n=a.size();
set < pl > lis;
vector < ll > tr(n,1);
for(int i=n-1; i>=0; i--){
auto p = lis.upper_bound({a[i],1e15});
if(p!=lis.end()){
tr[i]+=p->s;
}
lis.insert({a[i],tr[i]});
auto pp = lis.find({a[i],tr[i]});
if(next(pp)!=lis.end() and (next(pp)->s == tr[i])) lis.erase(pp);
else if(pp!=lis.begin() and (prev(pp)->s == tr[i])) lis.erase(prev(pp));
}
ll ans = *max_element(all(tr));
//for(auto k: tr) cout << k << ' ';
//cout << endl;
set < pl > Lis;
for(int i=0; i<n-1; i++){
auto p = Lis.upper_bound({a[i]-x,0});
if(p!=Lis.end()){
if(p->f > a[i]-x){
Lis.insert({a[i]-x, p->s});
Lis.erase(p);
}
}
else Lis.insert({a[i]-x, Lis.size()+1});
auto w = Lis.lower_bound({a[i+1],0});
ll ct=Lis.size();
if(w!=Lis.end()) ct = (w->s)-1;
ans = max(ans, ct + tr[i+1]);
}
cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
//freopen("nocross.in", "r", stdin);
//freopen("nocross.out", "w", stdout);
int n; ll x;
cin >> n >> x;
vector < ll > a(n);
for(auto &w: a) cin >> w;
trad(a,x);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
5092 KB |
Output is correct |
2 |
Correct |
123 ms |
5032 KB |
Output is correct |
3 |
Correct |
122 ms |
5060 KB |
Output is correct |
4 |
Correct |
122 ms |
5088 KB |
Output is correct |
5 |
Correct |
189 ms |
17604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
1484 KB |
Output is correct |
2 |
Correct |
28 ms |
1536 KB |
Output is correct |
3 |
Correct |
28 ms |
1540 KB |
Output is correct |
4 |
Correct |
34 ms |
4544 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
40 ms |
4972 KB |
Output is correct |
7 |
Correct |
23 ms |
1996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
2644 KB |
Output is correct |
2 |
Correct |
53 ms |
2708 KB |
Output is correct |
3 |
Correct |
111 ms |
5056 KB |
Output is correct |
4 |
Correct |
166 ms |
17452 KB |
Output is correct |
5 |
Correct |
89 ms |
8940 KB |
Output is correct |
6 |
Correct |
136 ms |
16692 KB |
Output is correct |
7 |
Correct |
142 ms |
18528 KB |
Output is correct |
8 |
Correct |
45 ms |
3660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
316 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
124 ms |
5092 KB |
Output is correct |
28 |
Correct |
123 ms |
5032 KB |
Output is correct |
29 |
Correct |
122 ms |
5060 KB |
Output is correct |
30 |
Correct |
122 ms |
5088 KB |
Output is correct |
31 |
Correct |
189 ms |
17604 KB |
Output is correct |
32 |
Correct |
28 ms |
1484 KB |
Output is correct |
33 |
Correct |
28 ms |
1536 KB |
Output is correct |
34 |
Correct |
28 ms |
1540 KB |
Output is correct |
35 |
Correct |
34 ms |
4544 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
40 ms |
4972 KB |
Output is correct |
38 |
Correct |
23 ms |
1996 KB |
Output is correct |
39 |
Correct |
56 ms |
2644 KB |
Output is correct |
40 |
Correct |
53 ms |
2708 KB |
Output is correct |
41 |
Correct |
111 ms |
5056 KB |
Output is correct |
42 |
Correct |
166 ms |
17452 KB |
Output is correct |
43 |
Correct |
89 ms |
8940 KB |
Output is correct |
44 |
Correct |
136 ms |
16692 KB |
Output is correct |
45 |
Correct |
142 ms |
18528 KB |
Output is correct |
46 |
Correct |
45 ms |
3660 KB |
Output is correct |
47 |
Correct |
59 ms |
3660 KB |
Output is correct |
48 |
Correct |
59 ms |
3692 KB |
Output is correct |
49 |
Correct |
126 ms |
7104 KB |
Output is correct |
50 |
Correct |
162 ms |
18628 KB |
Output is correct |
51 |
Correct |
132 ms |
17096 KB |
Output is correct |
52 |
Correct |
198 ms |
18756 KB |
Output is correct |
53 |
Correct |
142 ms |
18764 KB |
Output is correct |
54 |
Correct |
147 ms |
19464 KB |
Output is correct |
55 |
Correct |
100 ms |
7000 KB |
Output is correct |