比赛 20091026 评测结果 AAAAAAAATA
题目名称 货物搬运 最终得分 90
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-10-26 20:14:35
显示代码纯文本
program move;
var
  a,b:array[1..10001] of longint;
  n,i,j,temp:integer;
  he,pingjun,min,s:longint;
begin
  assign(input,'move.in');
  reset(input);
  assign(output,'move.out');
  rewrite(output);
  readln(n);
  for i:=1 to n do
  begin
    read(a[i]);
    he:=he+a[i];
  end;
  pingjun:=he div n;
  min:=maxlongint;
  for i:=1 to n do
  begin
    temp:=a[1];
    for j:=1 to n-1 do
      a[j]:=a[j+1];
    a[n]:=temp;
    s:=0;
    b:=a;
    for j:=1 to n-1 do
    begin
      if b[j]>=pingjun then
      begin
        s:=s+(b[j]-pingjun);
        b[j+1]:=b[j+1]+(b[j]-pingjun)
      end
      else
      begin
        s:=s+(pingjun-b[j]);
        b[j+1]:=b[j+1]-(pingjun-b[j])
      end
    end;
    if s<min
      then min:=s
  end;
  writeln(min);
  close(input);
  close(output)
end.