#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3+3, inf = INT_MAX;
int n, m, mx, a[N], dp[N][N];
// dp[i][j] = altura maxima que puedes conseguir en la plataforma i con j movimientos
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
int x = -inf;
if (dp[i-1][j] + m >= a[i]) x = max(x, a[i]);
if (j && dp[i-1][j-1] != -inf) x = max(x, dp[i-1][j-1] + m);
dp[i][j] = x;
}
}
int ans = inf;
for (int i = 0; i <= n; i++) {
if (dp[n][i] != -inf) {
ans = i;
break;
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
27 ms |
80504 KB |
Output is correct |
21 |
Correct |
34 ms |
98128 KB |
Output is correct |
22 |
Correct |
28 ms |
98140 KB |
Output is correct |
23 |
Correct |
29 ms |
98140 KB |
Output is correct |
24 |
Correct |
28 ms |
98140 KB |
Output is correct |
25 |
Correct |
28 ms |
98128 KB |
Output is correct |
26 |
Correct |
28 ms |
98156 KB |
Output is correct |
27 |
Correct |
29 ms |
98392 KB |
Output is correct |
28 |
Correct |
28 ms |
98140 KB |
Output is correct |
29 |
Correct |
28 ms |
98140 KB |
Output is correct |
30 |
Correct |
28 ms |
98140 KB |
Output is correct |
31 |
Correct |
28 ms |
98140 KB |
Output is correct |
32 |
Correct |
28 ms |
98128 KB |
Output is correct |
33 |
Correct |
29 ms |
98216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
27 ms |
80504 KB |
Output is correct |
5 |
Correct |
34 ms |
98128 KB |
Output is correct |
6 |
Correct |
28 ms |
98140 KB |
Output is correct |
7 |
Correct |
29 ms |
98140 KB |
Output is correct |
8 |
Correct |
28 ms |
98140 KB |
Output is correct |
9 |
Correct |
28 ms |
98128 KB |
Output is correct |
10 |
Correct |
28 ms |
98156 KB |
Output is correct |
11 |
Correct |
29 ms |
98392 KB |
Output is correct |
12 |
Correct |
28 ms |
98140 KB |
Output is correct |
13 |
Correct |
28 ms |
98140 KB |
Output is correct |
14 |
Correct |
28 ms |
98140 KB |
Output is correct |
15 |
Correct |
28 ms |
98140 KB |
Output is correct |
16 |
Correct |
28 ms |
98128 KB |
Output is correct |
17 |
Correct |
29 ms |
98216 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
0 ms |
2396 KB |
Output is correct |
34 |
Correct |
29 ms |
98208 KB |
Output is correct |
35 |
Correct |
28 ms |
98172 KB |
Output is correct |
36 |
Correct |
30 ms |
98148 KB |
Output is correct |
37 |
Correct |
28 ms |
98188 KB |
Output is correct |
38 |
Correct |
29 ms |
98132 KB |
Output is correct |
39 |
Correct |
28 ms |
98128 KB |
Output is correct |
40 |
Correct |
28 ms |
98196 KB |
Output is correct |
41 |
Correct |
29 ms |
98192 KB |
Output is correct |
42 |
Correct |
33 ms |
98120 KB |
Output is correct |
43 |
Correct |
28 ms |
98228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
98208 KB |
Output is correct |
2 |
Correct |
28 ms |
98172 KB |
Output is correct |
3 |
Correct |
30 ms |
98148 KB |
Output is correct |
4 |
Correct |
28 ms |
98188 KB |
Output is correct |
5 |
Correct |
29 ms |
98132 KB |
Output is correct |
6 |
Correct |
28 ms |
98128 KB |
Output is correct |
7 |
Correct |
28 ms |
98196 KB |
Output is correct |
8 |
Correct |
29 ms |
98192 KB |
Output is correct |
9 |
Correct |
33 ms |
98120 KB |
Output is correct |
10 |
Correct |
28 ms |
98228 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
27 ms |
80504 KB |
Output is correct |
15 |
Correct |
34 ms |
98128 KB |
Output is correct |
16 |
Correct |
28 ms |
98140 KB |
Output is correct |
17 |
Correct |
29 ms |
98140 KB |
Output is correct |
18 |
Correct |
28 ms |
98140 KB |
Output is correct |
19 |
Correct |
28 ms |
98128 KB |
Output is correct |
20 |
Correct |
28 ms |
98156 KB |
Output is correct |
21 |
Correct |
29 ms |
98392 KB |
Output is correct |
22 |
Correct |
28 ms |
98140 KB |
Output is correct |
23 |
Correct |
28 ms |
98140 KB |
Output is correct |
24 |
Correct |
28 ms |
98140 KB |
Output is correct |
25 |
Correct |
28 ms |
98140 KB |
Output is correct |
26 |
Correct |
28 ms |
98128 KB |
Output is correct |
27 |
Correct |
29 ms |
98216 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Runtime error |
3 ms |
728 KB |
Execution killed with signal 11 |
46 |
Halted |
0 ms |
0 KB |
- |