这是标程
var n,k,i,x,j,v:longint;
a:array[1..101] of longint;
dis:array[1..101] of longint;
f:array[1..101,1..101] of longint;
function ok(x,y:longint):longint;
var min,i,t,j:longint;
begin
min:=maxlongint;
for i:=x to y do begin
t:=0;
for j:=x to y do t:=t+abs(dis[j]-dis[i])*a[j];
if t<min then min:=t;
end;
exit(min);
end;
begin
readln(n,k);
for i:=1 to n do read(a[i]);
for i:=2 to n do begin
read(x);
dis[i]:=dis[i-1]+x;
end;
for i:=1 to n do f[i,1]:=ok(1,i);
for j:=2 to k do begin
for i:=j to n do begin
f[i,j]:=f[i-1,j-1];
for v:=j to i-1 do begin
if f[v-1,j-1]+ok(v,i)<f[i,j] then
f[i,j]:=f[v-1,j-1]+ok(v,i);
end;
end;
end;
writeln(f[n,k]);
end.