#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename K> using hset = gp_hash_table<K, null_type>;
template<typename K, typename V> using hmap = gp_hash_table<K, V>;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define smax(x, y) (x = max(x, y))
#define smin(x, y) (x = min(x, y))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
using ll = long long;
using ld = long double;
template<typename T>
using vv = vector<vector<T>>;
using vi = vector<int>;
using ii = array<int, 2>;
using vii = vector<ii>;
using vvi = vv<int>;
using vll = vector<ll>;
using l2 = array<ll, 2>;
using vl2 = vector<l2>;
using vvll = vv<ll>;
template<typename T>
using minq = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using maxq = priority_queue<T>;
template<typename T>
using oset = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
const ll M = 1000000007;
const ll infll = M * M;
template<typename IN>
IN discrete_binary_search(function<bool(IN)> predicate, IN low = 0, IN high = numeric_limits<IN>::max()) {
while (low < high) {
IN middle = low + (high - low) / 2; // todo std::midpoint in cpp 2020
if (predicate(middle))
high = middle;
else low = middle + 1;
}
return low;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, x;
cin >> n >> x;
vll t(n);
F0R(i, n) cin >> t[i];
vi plis(n), slds(n);
vll idp(n+1, infll);
idp[0] = -infll;
F0R(i, n) {
plis[i] = lower_bound(all(idp), t[i]) - idp.begin();
*lower_bound(all(idp), t[i]-x) = t[i]-x;
}
vll ddp(n+1, -infll);
ddp[0] = infll;
R0F(i, n) {
int j = discrete_binary_search<int>([&](int j) -> bool {
return ddp[j] <= t[i];
}, 0, n);
ddp[j] = t[i];
slds[i] = j;
}
int res = -1;
F0R(i, n) smax(res, plis[i] + slds[i] -1);
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
312 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 |
344 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 |
64 ms |
6688 KB |
Output is correct |
2 |
Correct |
64 ms |
6688 KB |
Output is correct |
3 |
Correct |
64 ms |
6636 KB |
Output is correct |
4 |
Correct |
69 ms |
6632 KB |
Output is correct |
5 |
Correct |
49 ms |
6596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
2008 KB |
Output is correct |
2 |
Correct |
15 ms |
2360 KB |
Output is correct |
3 |
Correct |
15 ms |
2360 KB |
Output is correct |
4 |
Correct |
13 ms |
2132 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
13 ms |
2176 KB |
Output is correct |
7 |
Correct |
13 ms |
2368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
3660 KB |
Output is correct |
2 |
Correct |
33 ms |
3592 KB |
Output is correct |
3 |
Correct |
61 ms |
6688 KB |
Output is correct |
4 |
Correct |
51 ms |
6704 KB |
Output is correct |
5 |
Correct |
25 ms |
3568 KB |
Output is correct |
6 |
Correct |
43 ms |
6348 KB |
Output is correct |
7 |
Correct |
46 ms |
6308 KB |
Output is correct |
8 |
Correct |
25 ms |
3532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
312 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
312 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
64 ms |
6688 KB |
Output is correct |
28 |
Correct |
64 ms |
6688 KB |
Output is correct |
29 |
Correct |
64 ms |
6636 KB |
Output is correct |
30 |
Correct |
69 ms |
6632 KB |
Output is correct |
31 |
Correct |
49 ms |
6596 KB |
Output is correct |
32 |
Correct |
15 ms |
2008 KB |
Output is correct |
33 |
Correct |
15 ms |
2360 KB |
Output is correct |
34 |
Correct |
15 ms |
2360 KB |
Output is correct |
35 |
Correct |
13 ms |
2132 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
13 ms |
2176 KB |
Output is correct |
38 |
Correct |
13 ms |
2368 KB |
Output is correct |
39 |
Correct |
29 ms |
3660 KB |
Output is correct |
40 |
Correct |
33 ms |
3592 KB |
Output is correct |
41 |
Correct |
61 ms |
6688 KB |
Output is correct |
42 |
Correct |
51 ms |
6704 KB |
Output is correct |
43 |
Correct |
25 ms |
3568 KB |
Output is correct |
44 |
Correct |
43 ms |
6348 KB |
Output is correct |
45 |
Correct |
46 ms |
6308 KB |
Output is correct |
46 |
Correct |
25 ms |
3532 KB |
Output is correct |
47 |
Correct |
34 ms |
4292 KB |
Output is correct |
48 |
Correct |
32 ms |
4292 KB |
Output is correct |
49 |
Correct |
65 ms |
8380 KB |
Output is correct |
50 |
Correct |
51 ms |
7616 KB |
Output is correct |
51 |
Correct |
41 ms |
5808 KB |
Output is correct |
52 |
Correct |
50 ms |
7744 KB |
Output is correct |
53 |
Correct |
48 ms |
7736 KB |
Output is correct |
54 |
Correct |
50 ms |
8520 KB |
Output is correct |
55 |
Correct |
54 ms |
8504 KB |
Output is correct |