/*
ॐ नमो भगवते वासुदेवाय नमः
ॐ भूर्भुव: स्व: तत्सवितुर्वरेण्यं भर्गो देवस्य धीमहि धियो यो न: प्रचोदयात्।
*/
// all hail Infront of almighty lord krishna (jai shri krishna ji)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
const long long INF =1e18;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
template<typename T>
using ordered_multiset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int N=1e5 + 10;
const int mod = 998244353;
void Solve()
{
int n,x;
cin>>n>>x;
vector<int>a(n);
for(int i=0;i<n;i++)
{
cin>>a[i];
}
vector<int>inc(n,1);
vector<int>dp(n,1e12);
int ans=0;
for(int i=0;i<n;i++)
{
auto j=lower_bound(dp.begin(),dp.end(),a[i])-dp.begin();
inc[i]=j+1;
dp[j]=a[i];
ans=max(ans,inc[i]);
}
fill(dp.begin(),dp.end(),1e12);
for(int i=n-1;i>=0;i--)
{
auto it=lower_bound(dp.begin(),dp.end(),-a[i]+x)-dp.begin();
ans=max(ans,inc[i]+it);
it=lower_bound(dp.begin(),dp.end(),-a[i])-dp.begin();
dp[it]=-a[i];
}
cout<<ans<<"\n";
}
signed main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout<<fixed;
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
// cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
// cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 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 |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
7004 KB |
Output is correct |
2 |
Correct |
40 ms |
7004 KB |
Output is correct |
3 |
Correct |
34 ms |
7004 KB |
Output is correct |
4 |
Correct |
42 ms |
7012 KB |
Output is correct |
5 |
Correct |
25 ms |
6236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1884 KB |
Output is correct |
2 |
Correct |
8 ms |
2132 KB |
Output is correct |
3 |
Correct |
9 ms |
1884 KB |
Output is correct |
4 |
Correct |
6 ms |
1924 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
7 ms |
1884 KB |
Output is correct |
7 |
Correct |
7 ms |
2136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
3676 KB |
Output is correct |
2 |
Correct |
16 ms |
3784 KB |
Output is correct |
3 |
Correct |
36 ms |
7004 KB |
Output is correct |
4 |
Correct |
27 ms |
6236 KB |
Output is correct |
5 |
Correct |
14 ms |
3160 KB |
Output is correct |
6 |
Correct |
24 ms |
5976 KB |
Output is correct |
7 |
Correct |
25 ms |
6748 KB |
Output is correct |
8 |
Correct |
13 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
348 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
604 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 |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 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 |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
35 ms |
7004 KB |
Output is correct |
28 |
Correct |
40 ms |
7004 KB |
Output is correct |
29 |
Correct |
34 ms |
7004 KB |
Output is correct |
30 |
Correct |
42 ms |
7012 KB |
Output is correct |
31 |
Correct |
25 ms |
6236 KB |
Output is correct |
32 |
Correct |
9 ms |
1884 KB |
Output is correct |
33 |
Correct |
8 ms |
2132 KB |
Output is correct |
34 |
Correct |
9 ms |
1884 KB |
Output is correct |
35 |
Correct |
6 ms |
1924 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
7 ms |
1884 KB |
Output is correct |
38 |
Correct |
7 ms |
2136 KB |
Output is correct |
39 |
Correct |
16 ms |
3676 KB |
Output is correct |
40 |
Correct |
16 ms |
3784 KB |
Output is correct |
41 |
Correct |
36 ms |
7004 KB |
Output is correct |
42 |
Correct |
27 ms |
6236 KB |
Output is correct |
43 |
Correct |
14 ms |
3160 KB |
Output is correct |
44 |
Correct |
24 ms |
5976 KB |
Output is correct |
45 |
Correct |
25 ms |
6748 KB |
Output is correct |
46 |
Correct |
13 ms |
3676 KB |
Output is correct |
47 |
Correct |
18 ms |
3676 KB |
Output is correct |
48 |
Correct |
19 ms |
3792 KB |
Output is correct |
49 |
Correct |
34 ms |
7008 KB |
Output is correct |
50 |
Correct |
26 ms |
6236 KB |
Output is correct |
51 |
Correct |
28 ms |
4700 KB |
Output is correct |
52 |
Correct |
26 ms |
6236 KB |
Output is correct |
53 |
Correct |
25 ms |
6236 KB |
Output is correct |
54 |
Correct |
26 ms |
7068 KB |
Output is correct |
55 |
Correct |
29 ms |
7020 KB |
Output is correct |