比赛 20110414pm 评测结果 AWWWWWWWWW
题目名称 气象牛 最终得分 10
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-04-14 17:18:10
显示代码纯文本
program baric;
var
  f:array[0..110,0..110] of int64;
  sum,a:array[0..110] of longint;
  n,e,i,j,k:longint;

function min(x,y:int64):int64;
begin
  if x<y then min:=x else min:=y;
end;

begin
  assign(input,'baric.in');
  reset(input);
  assign(output,'baric.out');
  rewrite(output);

  readln(n,e);
  sum[0]:=0;
  for i:=1 to n do
  begin
    read(a[i]);
    sum[i]:=sum[i-1]+a[i];
  end;

  for i:=1 to n do
    f[i,1]:=abs(2*(i-1)*a[i]-2*sum[i-1]);

  for j:=2 to n do
    for i:=j to n do
    begin
      f[i,j]:=maxlongint;
      for k:=j-1 to i-1 do
        f[i,j]:=min(f[i,j],f[k,j-1]+abs((sum[i-1]-sum[k])*2-(i-k-1)*(a[i]+a[k])));
    end;

  for j:=2 to n+1 do
  begin
    f[n+1,j]:=maxlongint;
    for i:=j-1 to n do
      f[n+1,j]:=min(f[n+1,j],f[i,j-1]+abs((sum[n]-sum[i])*2-2*(n-i)*a[i]));
    if f[n+1,j]<=e then
    begin
      writeln(j-1,' ',f[n+1,j]);
      break;
    end;
  end;

  close(input);
  close(output);
end.