比赛 NOIP2008集训模拟3 评测结果 WWWTEEEEEW
题目名称 工作分配 最终得分 0
用户昵称 Achilles 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-12 10:47:34
显示代码纯文本
program divide;
var
  min:array[1..1000,1..1000]of integer;
  sz:array[0..1000]of integer;
  n,k,c,i,j,k2,maxt,mint:longint;
procedure qsort(a,b:integer);
var
  a2,b2,c,t,k:integer;
begin
  if a<b then begin
    c:=a;
    a2:=a;
    b2:=b;
    while a2<>b2 do
    begin
      while (sz[c]<=sz[b2])and(c<b2) do
        b2:=b2-1;
      sz[0]:=sz[c];
      sz[c]:=sz[b2];
      sz[b2]:=sz[0];
      c:=b2;
      while (sz[c]>=sz[a2])and(c>a2) do
        a2:=a2+1;
      sz[0]:=sz[c];
      sz[c]:=sz[a2];
      sz[a2]:=sz[0];
      c:=a2;
    end;
    qsort(a,a2-1);
    qsort(b2+1,b);
  end;
end;
begin
  assign(input,'divide.in');
  assign(output,'divide.out');
  reset(input);
  rewrite(output);
  readln(n,k,c);
  for i:=1 to n do
    read(sz[i]);
  qsort(1,n);
  for i:=1 to n do
    for j:=i to n do
    begin
      maxt:=0;
      mint:=32767;
      for k2:=i to j do
      begin
        if sz[k2]>maxt then maxt:=sz[k2];
        if sz[k2]<mint then mint:=sz[k2];
      end;
      min[i,j]:=c+(maxt-mint)*(maxt-mint);
    end;
  for i:=k to n-k do
  begin
    for j:=1 to n-i do
    begin
      for k2:=j+k-1 to j+i-k do
      begin
        if min[j,k2]+min[k2+1,j+i]<min[j,j+i] then begin
          min[j,j+i]:=min[j,k2]+min[k2+1,j+i];
        end;
      end;
    end;
  end;
  writeln(min[1,n]);
  close(input);
  close(output);
end.