比赛 10101115 评测结果 AWWWWWWWWW
题目名称 矩形分割 最终得分 10
用户昵称 donny 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 09:02:37
显示代码纯文本
program chocolate;
var
  a:array[1..20000,1..2]of longint;
  i,j,k,l:longint;
  n,m:longint;
  min:longint;
  x,y:longint;
procedure sort(x,y:longint);
var
  i,j,k,l:longint;
begin
  i:=x;
  j:=y;
  k:=a[(x+y) div 2,1];
  repeat
    while a[i,1]>k do inc(i);
    while a[j,1]<k do dec(j);
    if i<=j then
    begin
      l:=a[i,1];
      a[i,1]:=a[j,1];
      a[j,1]:=l;
      l:=a[i,2];
      a[i,2]:=a[j,2];
      a[j,2]:=l;
      inc(i);
      dec(j);
    end;
  until i>j;
  if x<j then sort(x,j);
  if i<y then sort(i,y);
end;
begin
  assign(input,'cut.in');
  reset(input);
  assign(output,'cut.out');
  rewrite(output);
  readln(n,m);
  for i:=1 to n-1 do
  begin
    readln(a[i,1]);
    a[i,2]:=1;
  end;
  for i:=1 to m-1 do
  begin
    readln(a[n+i-1,1]);
    a[n+i-1,2]:=2;
  end;
  sort(1,n+m-2);
  x:=1;
  y:=1;
  min:=0;
  for i:=1 to n+m-2 do
  begin
    case a[i,2] of
    1:begin
      min:=min+a[i,1]*y;
      inc(x);
    end;
    2:begin
      min:=min+a[i,1]*x;
      inc(y);
    end;
    end;
  end;
  writeln(min);
  close(input);
  close(output);
end.