#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
void setIO(string name="") {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".in", "r")) {
freopen(file".in", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const int N = 2e5+5;
int n, x, a[N], lb[N], rb[N], dp[N];
int main() {
setIO();
cin >> n >> x;
foru(i, 1, n) cin >> a[i];
a[n+1] = (int)1e9+1;
foru(i, 1, n) dp[i] = INT_MAX;
foru(i, 1, n) {
int pos = 0;
for(int z=n>>1; z>=1; z>>=1)
while (pos+z <= n && dp[pos+z] < a[i])
pos += z;
dp[pos+1] = a[i];
for(int z=n>>1; z>=1; z>>=1)
while (lb[i]+z <= n && dp[lb[i]+z] < a[i+1]+x)
lb[i] += z;
}
foru(i, 1, n) dp[i] = INT_MIN;
ford(i, n, 1) {
int pos = 0;
for(int z=n>>1; z>=1; z>>=1)
while (pos+z <= n && dp[pos+z] > a[i])
pos += z;
dp[pos+1] = a[i];
rb[i] = pos+1;
}
int ans = 0;
foru(i, 1, n) ans = max(ans, lb[i] + rb[i+1]);
cout << ans;
}
Compilation message
glo.cpp: In function 'void setIO(std::string)':
glo.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(file".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | freopen(file".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
280 KB |
Output is correct |
23 |
Correct |
1 ms |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
4068 KB |
Output is correct |
2 |
Correct |
54 ms |
3612 KB |
Output is correct |
3 |
Correct |
59 ms |
3700 KB |
Output is correct |
4 |
Correct |
53 ms |
3648 KB |
Output is correct |
5 |
Correct |
41 ms |
3608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1484 KB |
Output is correct |
2 |
Correct |
13 ms |
1360 KB |
Output is correct |
3 |
Correct |
12 ms |
1360 KB |
Output is correct |
4 |
Correct |
11 ms |
1352 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
11 ms |
1360 KB |
Output is correct |
7 |
Correct |
11 ms |
1344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
2440 KB |
Output is correct |
2 |
Correct |
24 ms |
2812 KB |
Output is correct |
3 |
Correct |
55 ms |
5352 KB |
Output is correct |
4 |
Correct |
44 ms |
4496 KB |
Output is correct |
5 |
Correct |
21 ms |
2424 KB |
Output is correct |
6 |
Correct |
37 ms |
4428 KB |
Output is correct |
7 |
Correct |
40 ms |
5036 KB |
Output is correct |
8 |
Correct |
21 ms |
2856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
280 KB |
Output is correct |
23 |
Correct |
1 ms |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
58 ms |
4068 KB |
Output is correct |
28 |
Correct |
54 ms |
3612 KB |
Output is correct |
29 |
Correct |
59 ms |
3700 KB |
Output is correct |
30 |
Correct |
53 ms |
3648 KB |
Output is correct |
31 |
Correct |
41 ms |
3608 KB |
Output is correct |
32 |
Correct |
13 ms |
1484 KB |
Output is correct |
33 |
Correct |
13 ms |
1360 KB |
Output is correct |
34 |
Correct |
12 ms |
1360 KB |
Output is correct |
35 |
Correct |
11 ms |
1352 KB |
Output is correct |
36 |
Correct |
1 ms |
324 KB |
Output is correct |
37 |
Correct |
11 ms |
1360 KB |
Output is correct |
38 |
Correct |
11 ms |
1344 KB |
Output is correct |
39 |
Correct |
25 ms |
2440 KB |
Output is correct |
40 |
Correct |
24 ms |
2812 KB |
Output is correct |
41 |
Correct |
55 ms |
5352 KB |
Output is correct |
42 |
Correct |
44 ms |
4496 KB |
Output is correct |
43 |
Correct |
21 ms |
2424 KB |
Output is correct |
44 |
Correct |
37 ms |
4428 KB |
Output is correct |
45 |
Correct |
40 ms |
5036 KB |
Output is correct |
46 |
Correct |
21 ms |
2856 KB |
Output is correct |
47 |
Correct |
26 ms |
2788 KB |
Output is correct |
48 |
Correct |
26 ms |
2772 KB |
Output is correct |
49 |
Correct |
62 ms |
5332 KB |
Output is correct |
50 |
Correct |
44 ms |
4476 KB |
Output is correct |
51 |
Correct |
34 ms |
3400 KB |
Output is correct |
52 |
Correct |
44 ms |
4676 KB |
Output is correct |
53 |
Correct |
39 ms |
4688 KB |
Output is correct |
54 |
Correct |
41 ms |
5304 KB |
Output is correct |
55 |
Correct |
45 ms |
5292 KB |
Output is correct |