比赛 10101115 评测结果 AAAAAAAAAA
题目名称 矩形分割 最终得分 100
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 10:25:54
显示代码纯文本
var
  n,m,total,heng,shu,i:longint;
  a,b:array[0..10000]of longint;

    procedure sort(l,r: longint);
      var
         i,j,x,y: longint;
      begin
         i:=l;
         j:=r;
         x:=a[(l+r) div 2];
         repeat
           while a[i]>x do
            inc(i);
           while x>a[j] do
            dec(j);
           if not(i>j) then
             begin
                y:=a[i];
                a[i]:=a[j];
                a[j]:=y;
                y:=b[i];
                b[i]:=b[j];
                b[j]:=y;
                inc(i);
                j:=j-1;
             end;
         until i>j;
         if l<j then
           sort(l,j);
         if i<r then
           sort(i,r);
      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
    read(a[i]);
    b[i]:=2;
  end;
  for i:=n to n+m-2 do
  begin
    read(a[i]);
    b[i]:=1;
  end;
  sort(1,n+m-2);
  heng:=1;
  shu:=1;
  for i:=1 to n+m-2 do
  begin
    if b[i]=1 then
    begin
      inc(total,a[i]*heng);
      inc(shu);
    end
    else begin
      inc(total,a[i]*shu);
      inc(heng);
    end;
  end;
  writeln(total);
  close(input);
  close(output);
end.