This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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]);
} else {
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |