#include <bits/stdc++.h>
using i64 = long long;
constexpr int inf = 1001111111;
void chmax(int &a, int b) {
if (a < b) {
a = b;
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<int> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::vector dp(n + 1, std::vector<int>(n + 1, -inf));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (dp[i][j] == -inf) continue;
int x = dp[i][j];
if (a[i] - x <= m) {
chmax(dp[i + 1][j], a[i]);
}
chmax(dp[i + 1][j + 1], x + m);
}
}
for (int i = 0; i <= n; i++) {
if (dp[n][i] != -inf) {
std::cout << i << "\n";
return 0;
}
}
assert(false);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
57 ms |
64720 KB |
Output is correct |
21 |
Correct |
87 ms |
98380 KB |
Output is correct |
22 |
Correct |
50 ms |
98412 KB |
Output is correct |
23 |
Correct |
79 ms |
98352 KB |
Output is correct |
24 |
Correct |
88 ms |
98472 KB |
Output is correct |
25 |
Correct |
79 ms |
98380 KB |
Output is correct |
26 |
Correct |
87 ms |
98396 KB |
Output is correct |
27 |
Correct |
70 ms |
98392 KB |
Output is correct |
28 |
Correct |
88 ms |
98332 KB |
Output is correct |
29 |
Correct |
87 ms |
98380 KB |
Output is correct |
30 |
Correct |
79 ms |
98420 KB |
Output is correct |
31 |
Correct |
77 ms |
98332 KB |
Output is correct |
32 |
Correct |
75 ms |
98404 KB |
Output is correct |
33 |
Correct |
72 ms |
98376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
57 ms |
64720 KB |
Output is correct |
5 |
Correct |
87 ms |
98380 KB |
Output is correct |
6 |
Correct |
50 ms |
98412 KB |
Output is correct |
7 |
Correct |
79 ms |
98352 KB |
Output is correct |
8 |
Correct |
88 ms |
98472 KB |
Output is correct |
9 |
Correct |
79 ms |
98380 KB |
Output is correct |
10 |
Correct |
87 ms |
98396 KB |
Output is correct |
11 |
Correct |
70 ms |
98392 KB |
Output is correct |
12 |
Correct |
88 ms |
98332 KB |
Output is correct |
13 |
Correct |
87 ms |
98380 KB |
Output is correct |
14 |
Correct |
79 ms |
98420 KB |
Output is correct |
15 |
Correct |
77 ms |
98332 KB |
Output is correct |
16 |
Correct |
75 ms |
98404 KB |
Output is correct |
17 |
Correct |
72 ms |
98376 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
316 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
320 KB |
Output is correct |
34 |
Correct |
54 ms |
98452 KB |
Output is correct |
35 |
Correct |
48 ms |
98420 KB |
Output is correct |
36 |
Correct |
51 ms |
98360 KB |
Output is correct |
37 |
Correct |
84 ms |
98368 KB |
Output is correct |
38 |
Correct |
68 ms |
98420 KB |
Output is correct |
39 |
Correct |
88 ms |
98352 KB |
Output is correct |
40 |
Correct |
76 ms |
98420 KB |
Output is correct |
41 |
Correct |
53 ms |
98380 KB |
Output is correct |
42 |
Correct |
75 ms |
98352 KB |
Output is correct |
43 |
Correct |
76 ms |
98380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
98452 KB |
Output is correct |
2 |
Correct |
48 ms |
98420 KB |
Output is correct |
3 |
Correct |
51 ms |
98360 KB |
Output is correct |
4 |
Correct |
84 ms |
98368 KB |
Output is correct |
5 |
Correct |
68 ms |
98420 KB |
Output is correct |
6 |
Correct |
88 ms |
98352 KB |
Output is correct |
7 |
Correct |
76 ms |
98420 KB |
Output is correct |
8 |
Correct |
53 ms |
98380 KB |
Output is correct |
9 |
Correct |
75 ms |
98352 KB |
Output is correct |
10 |
Correct |
76 ms |
98380 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
57 ms |
64720 KB |
Output is correct |
15 |
Correct |
87 ms |
98380 KB |
Output is correct |
16 |
Correct |
50 ms |
98412 KB |
Output is correct |
17 |
Correct |
79 ms |
98352 KB |
Output is correct |
18 |
Correct |
88 ms |
98472 KB |
Output is correct |
19 |
Correct |
79 ms |
98380 KB |
Output is correct |
20 |
Correct |
87 ms |
98396 KB |
Output is correct |
21 |
Correct |
70 ms |
98392 KB |
Output is correct |
22 |
Correct |
88 ms |
98332 KB |
Output is correct |
23 |
Correct |
87 ms |
98380 KB |
Output is correct |
24 |
Correct |
79 ms |
98420 KB |
Output is correct |
25 |
Correct |
77 ms |
98332 KB |
Output is correct |
26 |
Correct |
75 ms |
98404 KB |
Output is correct |
27 |
Correct |
72 ms |
98376 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
316 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
320 KB |
Output is correct |
44 |
Runtime error |
107 ms |
262144 KB |
Execution killed with signal 9 |
45 |
Halted |
0 ms |
0 KB |
- |