记录编号 14430 评测结果 AAAAAAAAAA
题目名称 筷子 最终得分 100
用户昵称 Gravatarreamb 是否通过 通过
代码语言 Pascal 运行时间 0.003 s
提交时间 2009-10-29 16:39:18 内存使用 0.13 MiB
显示代码纯文本
program kuaizi;
var
  d,k,n,i,j:longint;
  a:array[1..100]of longint;
  f:array[0..100,0..50]of longint;
function min(a,b:longint):longint;
begin
  if a<b then
    min:=a
  else
    min:=b
end;
begin
  assign (input,'chop.in');
  reset (input);
  assign (output,'chop.out');
  rewrite (output);
  readln (n,k);
  for i:=1 to n do
    read (a[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
    if a[i]>a[j] then
    begin
      d:=a[i];
      a[i]:=a[j];
      a[j]:=d
    end;
  k:=k+3;
  for i:=0 to n do
    for j:=1 to k do
      f[i,j]:=999999999;
  for i:=0 to n do
    f[i,0]:=0;
  if k*2>n then writeln ('-1')
  else
  begin
    for i:=2 to n do
      for j:=1 to k do
        f[i,j]:=min(f[i-1,j],f[i-2,j-1]+sqr(a[i]-a[i-1]));
    writeln (f[n,k])
  end;
  close (input);
  close (output)
end.