#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define sz(v) (int)v.size()
#define ps(y) cout << fixed << setprecision(y)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define trav(x, v) for(auto &x: v)
#define w(t) int t; cin >> t; while(t--)
#define rep0(i, n) for(int i = 0; i < n; i++)
#define rrep0(i, n) for(int i = n - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define rrep1(i, n) for(int i = n; i > 0; i--)
#define inp(arr, n) rep0(i, n) cin >> arr[i];
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef map<ll, ll> mii;
typedef map<char, ll> mci;
typedef priority_queue<ll> pq_mx;
typedef priority_queue<ll, vi, greater<>> pq_mn;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> pbds;
/*
* find_by_order(i) -> returns an iterator to the element at ith position (0 based)
* order_of_key(i) -> returns the position of element i (0 based)
*/
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void fio() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
}
ll n, X, a[N], pre[N];
int lis() {
vi dp;
rep0(x, n) {
int y = lb(all(dp), a[x]) - dp.begin();
if (y == sz(dp)) dp.pb(a[x]);
else dp[y] = a[x];
pre[x] = y + 1;
}
return sz(dp);
}
int main() {
fio();
cin >> n >> X;
inp(a, n)
ll ans = lis();
vi dp;
rrep0(x, n) {
int y = lb(all(dp), -a[x] + X) - dp.begin();
ans = max(ans, pre[x] + y);
y = lb(all(dp), -a[x]) - dp.begin();
if (y == sz(dp)) dp.pb(-a[x]);
else dp[y] = -a[x];
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 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 |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 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 |
332 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
3384 KB |
Output is correct |
2 |
Correct |
60 ms |
5368 KB |
Output is correct |
3 |
Correct |
59 ms |
5380 KB |
Output is correct |
4 |
Correct |
58 ms |
5312 KB |
Output is correct |
5 |
Correct |
37 ms |
6412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1100 KB |
Output is correct |
2 |
Correct |
15 ms |
1504 KB |
Output is correct |
3 |
Correct |
16 ms |
1496 KB |
Output is correct |
4 |
Correct |
12 ms |
1852 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
9 ms |
1804 KB |
Output is correct |
7 |
Correct |
12 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1892 KB |
Output is correct |
2 |
Correct |
27 ms |
2752 KB |
Output is correct |
3 |
Correct |
54 ms |
5304 KB |
Output is correct |
4 |
Correct |
38 ms |
6412 KB |
Output is correct |
5 |
Correct |
21 ms |
3340 KB |
Output is correct |
6 |
Correct |
29 ms |
6212 KB |
Output is correct |
7 |
Correct |
40 ms |
6944 KB |
Output is correct |
8 |
Correct |
24 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 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 |
332 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 |
60 ms |
3384 KB |
Output is correct |
28 |
Correct |
60 ms |
5368 KB |
Output is correct |
29 |
Correct |
59 ms |
5380 KB |
Output is correct |
30 |
Correct |
58 ms |
5312 KB |
Output is correct |
31 |
Correct |
37 ms |
6412 KB |
Output is correct |
32 |
Correct |
18 ms |
1100 KB |
Output is correct |
33 |
Correct |
15 ms |
1504 KB |
Output is correct |
34 |
Correct |
16 ms |
1496 KB |
Output is correct |
35 |
Correct |
12 ms |
1852 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
9 ms |
1804 KB |
Output is correct |
38 |
Correct |
12 ms |
1612 KB |
Output is correct |
39 |
Correct |
26 ms |
1892 KB |
Output is correct |
40 |
Correct |
27 ms |
2752 KB |
Output is correct |
41 |
Correct |
54 ms |
5304 KB |
Output is correct |
42 |
Correct |
38 ms |
6412 KB |
Output is correct |
43 |
Correct |
21 ms |
3340 KB |
Output is correct |
44 |
Correct |
29 ms |
6212 KB |
Output is correct |
45 |
Correct |
40 ms |
6944 KB |
Output is correct |
46 |
Correct |
24 ms |
2892 KB |
Output is correct |
47 |
Correct |
35 ms |
2748 KB |
Output is correct |
48 |
Correct |
31 ms |
2824 KB |
Output is correct |
49 |
Correct |
57 ms |
5300 KB |
Output is correct |
50 |
Correct |
35 ms |
6304 KB |
Output is correct |
51 |
Correct |
31 ms |
5280 KB |
Output is correct |
52 |
Correct |
36 ms |
6448 KB |
Output is correct |
53 |
Correct |
34 ms |
6496 KB |
Output is correct |
54 |
Correct |
42 ms |
7132 KB |
Output is correct |
55 |
Correct |
47 ms |
5364 KB |
Output is correct |