#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
int pf[5001],dp[5001][5001];
int cost(int s,int e){
return (pf[e]-pf[s])*(e-s);
}
int solve(int s,int e,int k){
if(k==0){
return cost(s,e);
}
int res=INF;
int k1=k/2,k2=(k-1)/2;
for(int i=s+k1+1;i<=e-k2-1;i++){
res=min(res,solve(s,i,k1)+solve(i,e,k2));
}
return res;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,K;
cin>>N>>K;
vector<int>v(N);
for(int i=0;i<N;i++){
cin>>v[i];
}
for(int i=0;i<N;i++){
pf[i+1]=pf[i]+v[i];
}
cout<<solve(0,N,K)<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1844 KiB | ||||
2 | Time limit exceeded | 3.099s | 1432 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2440 KiB | ||||
4 | Accepted | 3ms | 2488 KiB | ||||
5 | Accepted | 3ms | 2832 KiB | ||||
6 | Accepted | 3ms | 2788 KiB | ||||
7 | Accepted | 3ms | 2972 KiB | ||||
subtask3 | 0/10 | ||||||
8 | Accepted | 354ms | 2940 KiB | ||||
9 | Time limit exceeded | 3.056s | 3172 KiB | ||||
10 | Time limit exceeded | 3.052s | 3140 KiB | ||||
11 | Time limit exceeded | 3.056s | 3376 KiB | ||||
12 | Time limit exceeded | 3.049s | 3332 KiB | ||||
subtask4 | 0/20 | ||||||
13 | Accepted | 216ms | 3556 KiB | ||||
14 | Time limit exceeded | 3.076s | 3696 KiB | ||||
15 | Time limit exceeded | 3.085s | 2948 KiB | ||||
16 | Time limit exceeded | 3.082s | 3268 KiB | ||||
17 | Time limit exceeded | 3.062s | 4220 KiB | ||||
18 | Time limit exceeded | 3.069s | 4632 KiB | ||||
subtask5 | 0/29 | ||||||
19 | Runtime error | 8ms | 5576 KiB | ||||
20 | Runtime error | 8ms | 5800 KiB | ||||
21 | Runtime error | 8ms | 6396 KiB | ||||
22 | Runtime error | 8ms | 6712 KiB | ||||
23 | Runtime error | 8ms | 7032 KiB | ||||
subtask6 | 0/31 | ||||||
24 | Runtime error | 16ms | 8604 KiB | ||||
25 | Runtime error | 16ms | 9344 KiB | ||||
26 | Runtime error | 16ms | 10096 KiB | ||||
27 | Runtime error | 16ms | 10892 KiB | ||||
28 | Runtime error | 16ms | 11536 KiB | ||||
29 | Runtime error | 16ms | 11972 KiB | ||||
30 | Runtime error | 16ms | 12768 KiB | ||||
31 | Runtime error | 16ms | 13444 KiB | ||||
32 | Runtime error | 16ms | 13996 KiB | ||||
33 | Runtime error | 16ms | 14696 KiB | ||||
34 | Runtime error | 16ms | 15364 KiB | ||||
35 | Runtime error | 16ms | 16036 KiB | ||||
36 | Runtime error | 16ms | 16712 KiB | ||||
37 | Runtime error | 16ms | 17384 KiB | ||||
38 | Runtime error | 16ms | 18056 KiB | ||||
39 | Runtime error | 16ms | 18600 KiB | ||||
40 | Runtime error | 16ms | 19404 KiB |