#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <map>
#define int long long
#define vi vector<int>
#define ii pair<int, int>
#define f first
#define s second
#define all(x) (x).begin(), (x).end()
#define P 31
#define mod 1'000'000'007
#define inf 1'000'000'000'000
#define pb push_back
#define str string
#define sz(x) (x).size()
#define vvi vector<vi>
#define fun function
#define oopt cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);
#define file freopen("problemname.in", "r", stdin); freopen("pr.out", "w", stdout);
#define dbg(v) cout << "Line(" << __LINE__ << ") -> " << #v << " = " << (v) << endl;
using namespace std;
template <class T, int SZ> using arr = array<T, SZ>;
void solve()
{
int n, x;
cin >> n >> x;
vi a(n);
for (int&v:a)
cin >> v;
vi lis(n, inf);
vi lds(n, inf);
vi rhs(n);
for (int i = n-1; i >= 0; i--)
{
a[i] = -a[i];
int ix = lower_bound(all(lds), a[i])-lds.begin();
lds[ix] = a[i];
rhs[i] = ix+1;
a[i] = -a[i];
// cout << i << " " << rhs[i] << "\n";
}
int rez = 0;
for (int i = 0; i < n; i++)
{
int ix = lower_bound(all(lis), a[i]+x)-lis.begin();
// cout << i << " " << ix << " " << rhs[i] << "\n";
rez = max(rez, ix+rhs[i]);
ix = lower_bound(all(lis), a[i])-lis.begin();
lis[ix] = a[i];
}
cout << rez << "\n";
}
signed main()
{
oopt;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
8532 KB |
Output is correct |
2 |
Correct |
57 ms |
8528 KB |
Output is correct |
3 |
Correct |
50 ms |
8528 KB |
Output is correct |
4 |
Correct |
50 ms |
8528 KB |
Output is correct |
5 |
Correct |
35 ms |
7752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
2384 KB |
Output is correct |
2 |
Correct |
12 ms |
2384 KB |
Output is correct |
3 |
Correct |
11 ms |
2384 KB |
Output is correct |
4 |
Correct |
10 ms |
2128 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
9 ms |
2308 KB |
Output is correct |
7 |
Correct |
11 ms |
2520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
4432 KB |
Output is correct |
2 |
Correct |
27 ms |
4432 KB |
Output is correct |
3 |
Correct |
44 ms |
8544 KB |
Output is correct |
4 |
Correct |
38 ms |
7760 KB |
Output is correct |
5 |
Correct |
19 ms |
4176 KB |
Output is correct |
6 |
Correct |
33 ms |
7436 KB |
Output is correct |
7 |
Correct |
38 ms |
8008 KB |
Output is correct |
8 |
Correct |
19 ms |
4432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
49 ms |
8532 KB |
Output is correct |
28 |
Correct |
57 ms |
8528 KB |
Output is correct |
29 |
Correct |
50 ms |
8528 KB |
Output is correct |
30 |
Correct |
50 ms |
8528 KB |
Output is correct |
31 |
Correct |
35 ms |
7752 KB |
Output is correct |
32 |
Correct |
12 ms |
2384 KB |
Output is correct |
33 |
Correct |
12 ms |
2384 KB |
Output is correct |
34 |
Correct |
11 ms |
2384 KB |
Output is correct |
35 |
Correct |
10 ms |
2128 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
9 ms |
2308 KB |
Output is correct |
38 |
Correct |
11 ms |
2520 KB |
Output is correct |
39 |
Correct |
22 ms |
4432 KB |
Output is correct |
40 |
Correct |
27 ms |
4432 KB |
Output is correct |
41 |
Correct |
44 ms |
8544 KB |
Output is correct |
42 |
Correct |
38 ms |
7760 KB |
Output is correct |
43 |
Correct |
19 ms |
4176 KB |
Output is correct |
44 |
Correct |
33 ms |
7436 KB |
Output is correct |
45 |
Correct |
38 ms |
8008 KB |
Output is correct |
46 |
Correct |
19 ms |
4432 KB |
Output is correct |
47 |
Correct |
24 ms |
4432 KB |
Output is correct |
48 |
Correct |
24 ms |
4424 KB |
Output is correct |
49 |
Correct |
56 ms |
8400 KB |
Output is correct |
50 |
Correct |
34 ms |
7760 KB |
Output is correct |
51 |
Correct |
30 ms |
5968 KB |
Output is correct |
52 |
Correct |
36 ms |
7760 KB |
Output is correct |
53 |
Correct |
36 ms |
7760 KB |
Output is correct |
54 |
Correct |
37 ms |
8520 KB |
Output is correct |
55 |
Correct |
41 ms |
8528 KB |
Output is correct |