#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define int long long
typedef int64_t ll;
typedef long double ld;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define RF(n) RFi(i,n)
#define RFi(i,n) RFl(i,0,n)
#define RFl(i,l,n) for(int i=n-1;i>=l;i--)
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define mem(v,x) memset(v,x,sizeof v)
#define ff first
#define ss second
#define mid ((l+r)>>1)
#define RAN(a,b) uniform_int_distribution<int> (a, b)(rng)
#define debug(x) (cerr << (#x) << " = " << x << "\n")
#define cmax(a,b) (a = max(a,b))
#define cmin(a,b) (a = min(a,b))
template <typename T> using max_heap = __gnu_pbds::priority_queue<T,less<T> >;
template <typename T> using min_heap = __gnu_pbds::priority_queue<T,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
int solve(int *arr, int n, int x){
int rev[n];
F(n) rev[i] = -arr[n-1-i];
int ans = 0;
pii suf[n]; // (length, greatest)
vector<int> v;
F(n){
int c = get_pos(v, rev[i]);
if(c == (int)v.size()){
v.pb(rev[i]);
}else{
cmin(v[c], rev[i]);
}
suf[n-1-i] = mp(c+1, -v[c]);
}
//F(n) printf("%d %d\n", suf[i].ff, suf[i].ss);
v.clear();
F(n){
int c = get_pos(v, arr[i]);
if( c == (int) v.size()){
v.pb(arr[i]);
}else{
cmin(v[c], arr[i]);
}
if(i == n-1) break;
int bruh = get_pos(v, suf[i+1].ss + x);
bruh += suf[i+1].ff;
cmax(ans, bruh);
//debug(bruh);
}
//cmax(ans, (int)v.size());
return ans;
}
signed main(){
int n,x;
cin >> n >> x;
int arr[n];
int rev[n];
F(n) cin >> arr[i];
F(n) rev[i] = -arr[n-1-i];
int ans = solve(arr, n, x);
//int ans2 = solve(rev, n, x);
printf("%lld", ans);
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:82:7: warning: variable 'rev' set but not used [-Wunused-but-set-variable]
82 | int rev[n];
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
244 KB |
Output is correct |
8 |
Correct |
0 ms |
204 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
244 KB |
Output is correct |
8 |
Correct |
0 ms |
204 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 |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
244 KB |
Output is correct |
8 |
Correct |
0 ms |
204 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 |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
296 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 |
102 ms |
8004 KB |
Output is correct |
2 |
Correct |
103 ms |
8008 KB |
Output is correct |
3 |
Correct |
114 ms |
8000 KB |
Output is correct |
4 |
Correct |
98 ms |
8020 KB |
Output is correct |
5 |
Correct |
65 ms |
9156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
2116 KB |
Output is correct |
2 |
Correct |
25 ms |
2216 KB |
Output is correct |
3 |
Correct |
24 ms |
2124 KB |
Output is correct |
4 |
Correct |
15 ms |
2636 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
15 ms |
2608 KB |
Output is correct |
7 |
Correct |
22 ms |
2224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
4152 KB |
Output is correct |
2 |
Correct |
46 ms |
4140 KB |
Output is correct |
3 |
Correct |
95 ms |
8008 KB |
Output is correct |
4 |
Correct |
75 ms |
9148 KB |
Output is correct |
5 |
Correct |
31 ms |
4800 KB |
Output is correct |
6 |
Correct |
60 ms |
8876 KB |
Output is correct |
7 |
Correct |
76 ms |
8764 KB |
Output is correct |
8 |
Correct |
44 ms |
4172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
244 KB |
Output is correct |
8 |
Correct |
0 ms |
204 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 |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
300 KB |
Output is correct |
24 |
Correct |
1 ms |
296 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
102 ms |
8004 KB |
Output is correct |
28 |
Correct |
103 ms |
8008 KB |
Output is correct |
29 |
Correct |
114 ms |
8000 KB |
Output is correct |
30 |
Correct |
98 ms |
8020 KB |
Output is correct |
31 |
Correct |
65 ms |
9156 KB |
Output is correct |
32 |
Correct |
29 ms |
2116 KB |
Output is correct |
33 |
Correct |
25 ms |
2216 KB |
Output is correct |
34 |
Correct |
24 ms |
2124 KB |
Output is correct |
35 |
Correct |
15 ms |
2636 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
15 ms |
2608 KB |
Output is correct |
38 |
Correct |
22 ms |
2224 KB |
Output is correct |
39 |
Correct |
47 ms |
4152 KB |
Output is correct |
40 |
Correct |
46 ms |
4140 KB |
Output is correct |
41 |
Correct |
95 ms |
8008 KB |
Output is correct |
42 |
Correct |
75 ms |
9148 KB |
Output is correct |
43 |
Correct |
31 ms |
4800 KB |
Output is correct |
44 |
Correct |
60 ms |
8876 KB |
Output is correct |
45 |
Correct |
76 ms |
8764 KB |
Output is correct |
46 |
Correct |
44 ms |
4172 KB |
Output is correct |
47 |
Correct |
51 ms |
5144 KB |
Output is correct |
48 |
Correct |
49 ms |
5148 KB |
Output is correct |
49 |
Correct |
100 ms |
10028 KB |
Output is correct |
50 |
Correct |
66 ms |
10416 KB |
Output is correct |
51 |
Correct |
49 ms |
8100 KB |
Output is correct |
52 |
Correct |
86 ms |
10432 KB |
Output is correct |
53 |
Correct |
62 ms |
10532 KB |
Output is correct |
54 |
Correct |
89 ms |
11180 KB |
Output is correct |
55 |
Correct |
95 ms |
10052 KB |
Output is correct |