比赛 20090927练习赛 评测结果 WAAAAAAAAA
题目名称 筷子 最终得分 90
用户昵称 ReimBurSe. 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-09-27 21:06:52
显示代码纯文本
Program chop;

Type
sc=array [0..100,0..100] of longint;
sc1=array [1..100] of longint;

Var
s:sc;
a:sc1;
i,j,p:longint;
n,m,k,temp,min,temp1:longint;

Begin
assign(input,'chop.in');
assign(output,'chop.out');
reset(input);
rewrite(output);
readln(n,k);
for i:=1 to n do read(a[i]);
for i:=1 to (n-1) do begin
 for j:=(i+1) to n do begin
  if a[i]>a[j] then begin
   temp:=a[j];
   a[j]:=a[i];
   a[i]:=temp;
  end;
 end;
end;
k:=k+3;
if (n div 2)<k then writeln('-1')
else begin
 for i:=0 to 100 do
  for j:=1 to 100 do
   s[i,j]:=9999999;
 for i:=1 to n do begin
  for j:=1 to k do begin
   s[i,j]:=s[i-1,j];
   for p:=1 to (i-1) do begin
    temp:=s[p-1,j-1]+(a[p]-a[i])*(a[p]-a[i]);
    if temp<s[i,j] then s[i,j]:=temp;
   end;
  end;
 end;
end;
writeln(s[n,k]);
close(input);
close(output);
End.