// CEOI18_glo
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 2e9 + 100;
const ll LINF = 1e18 + 100;
#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define endl '\n'
#define MAXN 200100
int n, x;
int a[MAXN];
int fw[MAXN];
int dp[MAXN];
int32_t main(void)
{
fast_io;
cin >> n >> x;
FOR(i, 0, n) cin >> a[i];
dp[0] = INF;
for (int i = n - 1; i >= 0; i--)
{
int pos = lower_bound(dp, dp + n + 1, a[i], greater<int>()) - dp;
fw[i] = pos;
dp[pos] = a[i];
}
int ans = 0;
fill(dp, dp + MAXN, INF);
dp[0] = -INF;
FOR(i, 0, n)
{
int pos = lower_bound(dp, dp + n + 1, a[i] + x) - dp - 1;
ans = max(ans, pos + fw[i]);
pos = lower_bound(dp, dp + n + 1, a[i]) - dp;
dp[pos] = a[i];
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1092 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1092 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1092 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
1 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
2644 KB |
Output is correct |
2 |
Correct |
62 ms |
2648 KB |
Output is correct |
3 |
Correct |
65 ms |
2552 KB |
Output is correct |
4 |
Correct |
61 ms |
2624 KB |
Output is correct |
5 |
Correct |
46 ms |
2616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1392 KB |
Output is correct |
2 |
Correct |
15 ms |
1484 KB |
Output is correct |
3 |
Correct |
15 ms |
1484 KB |
Output is correct |
4 |
Correct |
12 ms |
1484 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
12 ms |
1484 KB |
Output is correct |
7 |
Correct |
13 ms |
1440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1776 KB |
Output is correct |
2 |
Correct |
34 ms |
1804 KB |
Output is correct |
3 |
Correct |
59 ms |
2552 KB |
Output is correct |
4 |
Correct |
48 ms |
2568 KB |
Output is correct |
5 |
Correct |
24 ms |
1780 KB |
Output is correct |
6 |
Correct |
41 ms |
2564 KB |
Output is correct |
7 |
Correct |
50 ms |
2576 KB |
Output is correct |
8 |
Correct |
25 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1092 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1100 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
1 ms |
1100 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
1 ms |
1100 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
1100 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
1100 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
67 ms |
2644 KB |
Output is correct |
28 |
Correct |
62 ms |
2648 KB |
Output is correct |
29 |
Correct |
65 ms |
2552 KB |
Output is correct |
30 |
Correct |
61 ms |
2624 KB |
Output is correct |
31 |
Correct |
46 ms |
2616 KB |
Output is correct |
32 |
Correct |
15 ms |
1392 KB |
Output is correct |
33 |
Correct |
15 ms |
1484 KB |
Output is correct |
34 |
Correct |
15 ms |
1484 KB |
Output is correct |
35 |
Correct |
12 ms |
1484 KB |
Output is correct |
36 |
Correct |
1 ms |
1100 KB |
Output is correct |
37 |
Correct |
12 ms |
1484 KB |
Output is correct |
38 |
Correct |
13 ms |
1440 KB |
Output is correct |
39 |
Correct |
34 ms |
1776 KB |
Output is correct |
40 |
Correct |
34 ms |
1804 KB |
Output is correct |
41 |
Correct |
59 ms |
2552 KB |
Output is correct |
42 |
Correct |
48 ms |
2568 KB |
Output is correct |
43 |
Correct |
24 ms |
1780 KB |
Output is correct |
44 |
Correct |
41 ms |
2564 KB |
Output is correct |
45 |
Correct |
50 ms |
2576 KB |
Output is correct |
46 |
Correct |
25 ms |
1868 KB |
Output is correct |
47 |
Correct |
31 ms |
1816 KB |
Output is correct |
48 |
Correct |
30 ms |
1876 KB |
Output is correct |
49 |
Correct |
63 ms |
2628 KB |
Output is correct |
50 |
Correct |
45 ms |
2756 KB |
Output is correct |
51 |
Correct |
37 ms |
2380 KB |
Output is correct |
52 |
Correct |
49 ms |
2588 KB |
Output is correct |
53 |
Correct |
42 ms |
2628 KB |
Output is correct |
54 |
Correct |
47 ms |
2628 KB |
Output is correct |
55 |
Correct |
52 ms |
2628 KB |
Output is correct |