记录编号 102146 评测结果 AAAAAAAAAA
题目名称 [NOIP 2004]合并果子 最终得分 100
用户昵称 Gravatarhjt 是否通过 通过
代码语言 Pascal 运行时间 1.286 s
提交时间 2014-05-17 13:08:13 内存使用 0.18 MiB
显示代码纯文本
program fruit;
var sum,s,k,n:longint;
    a:array[0..10001] of longint;

procedure qsort(l,r:longint);
var i,j,m,p:longint;
begin
  i:=l;
  j:=r;
  m:=a[(l+r)div 2];
  repeat
    while a[i]<m do inc(i);
    while a[j]>m do dec(j);
    if i<=j then
    begin
      p:=a[i];
      a[i]:=a[j];
      a[j]:=p;
      inc(i);
      dec(j);
    end;
  until i>j;
  if i<r then qsort(i,r);
  if j>l then qsort(l,j);
end;

procedure insert(x,y:longint);
var i,j:longint; f:boolean;
begin
  for i:=x to y-1 do
  begin
    if a[i]>a[i+1] then begin j:=a[i];a[i]:=a[i+1];a[i+1]:=j; end;
  end;
end;

begin
  assign(input,'fruit.in');
  assign(output,'fruit.out');
  reset(input);
  rewrite(output);
  readln(n);
  for k:=1 to n do
    read(a[k]);
  qsort(1,n);
  for k:=1 to n-1 do
  begin
    a[k+1]:=a[k]+a[k+1];
    a[k]:=0;
    s:=a[k+1];
    sum:=sum+s;
    insert(K+1,n);
  end;
  writeln(sum);
 close(input);
  close(output);
end.