#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define int long long
const int maxn = 1e5 + 5;
const ll INF = 1e18;
signed main(void){
fastio;
int n, x;
cin>>n>>x;
vector<int> a(n);
for(int i = 0; i < n; i++) cin>>a[i];
vector<int> fr(n), bk(n);
vector<int> len;
for(int i = 0; i < n; i++){
int id = lower_bound(len.begin(), len.end(), a[i]) - len.begin();
if(id == len.size()) len.pb(a[i]);
else len[id] = a[i];
fr[i] = id + 1;
}
for(int i = 0; i < n; i++) a[i] *= -1;
len.clear();
for(int i = n - 1; i >= 0; i--){
int cur = lower_bound(len.begin(), len.end(), a[i] + x) - len.begin();
bk[i] = cur + 1;
int id = lower_bound(len.begin(), len.end(), a[i]) - len.begin();
if(id == len.size()) len.pb(a[i]);
else len[id] = a[i];
}
int ans = 0;
for(int i = 0; i < n; i++) ans = max(ans, fr[i] + bk[i] - 1);
cout<<ans<<"\n";
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:24:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(id == len.size()) len.pb(a[i]);
| ~~~^~~~~~~~~~~~~
glo.cpp:34:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | if(id == len.size()) len.pb(a[i]);
| ~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
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 |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
456 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
6384 KB |
Output is correct |
2 |
Correct |
49 ms |
6488 KB |
Output is correct |
3 |
Correct |
46 ms |
6236 KB |
Output is correct |
4 |
Correct |
46 ms |
6376 KB |
Output is correct |
5 |
Correct |
22 ms |
6868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2312 KB |
Output is correct |
2 |
Correct |
11 ms |
1884 KB |
Output is correct |
3 |
Correct |
10 ms |
2000 KB |
Output is correct |
4 |
Correct |
6 ms |
2140 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
2140 KB |
Output is correct |
7 |
Correct |
9 ms |
2004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
3420 KB |
Output is correct |
2 |
Correct |
20 ms |
3420 KB |
Output is correct |
3 |
Correct |
38 ms |
6388 KB |
Output is correct |
4 |
Correct |
23 ms |
6876 KB |
Output is correct |
5 |
Correct |
11 ms |
3976 KB |
Output is correct |
6 |
Correct |
19 ms |
6876 KB |
Output is correct |
7 |
Correct |
23 ms |
7132 KB |
Output is correct |
8 |
Correct |
15 ms |
3420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 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 |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
452 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 |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
456 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
46 ms |
6384 KB |
Output is correct |
28 |
Correct |
49 ms |
6488 KB |
Output is correct |
29 |
Correct |
46 ms |
6236 KB |
Output is correct |
30 |
Correct |
46 ms |
6376 KB |
Output is correct |
31 |
Correct |
22 ms |
6868 KB |
Output is correct |
32 |
Correct |
11 ms |
2312 KB |
Output is correct |
33 |
Correct |
11 ms |
1884 KB |
Output is correct |
34 |
Correct |
10 ms |
2000 KB |
Output is correct |
35 |
Correct |
6 ms |
2140 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
6 ms |
2140 KB |
Output is correct |
38 |
Correct |
9 ms |
2004 KB |
Output is correct |
39 |
Correct |
19 ms |
3420 KB |
Output is correct |
40 |
Correct |
20 ms |
3420 KB |
Output is correct |
41 |
Correct |
38 ms |
6388 KB |
Output is correct |
42 |
Correct |
23 ms |
6876 KB |
Output is correct |
43 |
Correct |
11 ms |
3976 KB |
Output is correct |
44 |
Correct |
19 ms |
6876 KB |
Output is correct |
45 |
Correct |
23 ms |
7132 KB |
Output is correct |
46 |
Correct |
15 ms |
3420 KB |
Output is correct |
47 |
Correct |
22 ms |
3420 KB |
Output is correct |
48 |
Correct |
22 ms |
3416 KB |
Output is correct |
49 |
Correct |
46 ms |
6228 KB |
Output is correct |
50 |
Correct |
23 ms |
6876 KB |
Output is correct |
51 |
Correct |
20 ms |
5852 KB |
Output is correct |
52 |
Correct |
22 ms |
7036 KB |
Output is correct |
53 |
Correct |
19 ms |
6864 KB |
Output is correct |
54 |
Correct |
24 ms |
7380 KB |
Output is correct |
55 |
Correct |
36 ms |
6236 KB |
Output is correct |