#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
vector<vector<vector<ll>>> dp;
vector<ll> pref_sum;
vector<int> a;
ll resz_osszeg(int i, int j){
return (pref_sum[j] - pref_sum[i-1]) * (j-i+1);
}
ll megold(int elso, int akt, int db){
if(akt == n){
return resz_osszeg(elso, n);
}
if(db == 0){
return resz_osszeg(elso, n);
}
if(dp[elso][akt][db] != -1){
return dp[elso][akt][db];
}
ll ki = megold(elso, akt+1, db);
ki = min(ki, megold(akt+1, akt+1, db-1) + resz_osszeg(elso, akt));
return ki;
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(NULL);
cin >> n >> k;
dp.assign(n+1, vector<vector<ll>>(n+1, vector<ll>(k+1, -1)));
a.resize(n+1);
for(int i = 1; i <= n; i++){
cin >> a[i];
}
pref_sum.resize(n+1);
pref_sum[0] = 0;
for(int i = 1; i <= n; i++){
pref_sum[i] = pref_sum[i-1] + a[i];
}
ll ret = megold(1, 1, k);
cout << ret << "\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1820 KiB | ||||
2 | Runtime error | 214ms | 524700 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2500 KiB | ||||
4 | Accepted | 3ms | 2616 KiB | ||||
5 | Accepted | 3ms | 2968 KiB | ||||
6 | Accepted | 4ms | 3320 KiB | ||||
7 | Accepted | 7ms | 3400 KiB | ||||
subtask3 | 0/10 | ||||||
8 | Time limit exceeded | 3.046s | 24204 KiB | ||||
9 | Time limit exceeded | 3.046s | 32152 KiB | ||||
10 | Time limit exceeded | 3.101s | 51824 KiB | ||||
11 | Time limit exceeded | 3.073s | 91460 KiB | ||||
12 | Time limit exceeded | 3.072s | 209856 KiB | ||||
subtask4 | 0/20 | ||||||
13 | Runtime error | 326ms | 522772 KiB | ||||
14 | Runtime error | 296ms | 522536 KiB | ||||
15 | Runtime error | 282ms | 522292 KiB | ||||
16 | Runtime error | 244ms | 522264 KiB | ||||
17 | Runtime error | 236ms | 522004 KiB | ||||
18 | Runtime error | 246ms | 521960 KiB | ||||
subtask5 | 0/29 | ||||||
19 | Runtime error | 305ms | 521916 KiB | ||||
20 | Runtime error | 224ms | 521860 KiB | ||||
21 | Runtime error | 256ms | 521852 KiB | ||||
22 | Runtime error | 245ms | 521892 KiB | ||||
23 | Runtime error | 194ms | 521908 KiB | ||||
subtask6 | 0/31 | ||||||
24 | Runtime error | 363ms | 521696 KiB | ||||
25 | Runtime error | 363ms | 521700 KiB | ||||
26 | Runtime error | 324ms | 521696 KiB | ||||
27 | Runtime error | 326ms | 521700 KiB | ||||
28 | Runtime error | 284ms | 521676 KiB | ||||
29 | Runtime error | 308ms | 521616 KiB | ||||
30 | Runtime error | 289ms | 521572 KiB | ||||
31 | Runtime error | 204ms | 521620 KiB | ||||
32 | Runtime error | 248ms | 521620 KiB | ||||
33 | Runtime error | 194ms | 521624 KiB | ||||
34 | Runtime error | 186ms | 521616 KiB | ||||
35 | Runtime error | 223ms | 521576 KiB | ||||
36 | Runtime error | 221ms | 521620 KiB | ||||
37 | Runtime error | 232ms | 521568 KiB | ||||
38 | Runtime error | 237ms | 521624 KiB | ||||
39 | Runtime error | 231ms | 521564 KiB | ||||
40 | Runtime error | 189ms | 521552 KiB |