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 <iostream>
#include <deque>
#include <set>
#include <cassert>
using namespace std;
const int INF = 1e9;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n, m; cin >> n >> m;
int a[n + 1]{};
for (int i = 1; i <= n; i++){
cin >> a[i];
}
int dp[n + 1][m + 1]{};
fill_n(&dp[0][0], sizeof(dp) / sizeof(int), INF);
deque<int> dq;
a[0] = INF;
dp[0][0] = 0;
dq.push_back(0);
multiset<int> st[m + 1]{};
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
int cur = a[i];
for (int k = i - 1; k >= 0; k--){
dp[i][j] = min(dp[i][j], dp[k][j - 1] + cur);
cur = max(cur, a[k]);
}
}
// while (dq.size() && a[dq.back()] < a[i]){
// int k = dq.back();
// dq.pop_back();
// for (int j = 1; j <= m; j++){
// assert(st[j - 1].find(dp[dq.back()][j - 1] + a[k]) != st[j - 1].end());
// st[j - 1].erase(st[j - 1].find(dp[dq.back()][j - 1] + a[k]));
// }
// }
// for (int j = 1; j <= m; j++){
// st[j - 1].insert(dp[dq.back()][j - 1] + a[i]);
// dp[i][j] = *st[j - 1].begin();
// }
// dq.push_back(i);
}
cout << dp[n][m] << '\n';
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... |