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 namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
using i64 = long long;
const int N = 1e5 + 10;
i64 dp[N][101]; // min val khi chia i phan tu vao j nhom
i64 a[N], pm[N];
void solve() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pm[i] = max(pm[i - 1], a[i]);
}
memset(dp, 127, sizeof dp);
for (int i = 1; i <= n; i++) {
dp[i][1] = pm[i];
}
for (int j = 2; j <= k; j++) {
for (int i = j; i <= n; i++) {
i64 t = a[i];
for (int p = i; p >= 1; p--) {
t = max(t, a[p]);
dp[i][j] = min(dp[i][j], dp[p - 1][j - 1] + t);
}
}
}
cout << dp[n][k];
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int TC = 1;
// cin >> TC;
while (TC--) {
solve();
}
}
# | 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... |