比赛 10101115 评测结果 AWWWWWWWWA
题目名称 矩形分割 最终得分 20
用户昵称 Des. 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 09:04:24
显示代码纯文本
program cut;
var a,b:array[0..2000]of int64;
    t,k,m,n,i,j:longint;
    an:int64;
procedure qsorta(l,r:longint);
var t,k:longint;
    i,c:int64;
begin
t:=l;
k:=r;
i:=a[(l+r)div 2];
repeat
  while a[t]<i do inc(t);
  while a[k]>i do dec(k);
  if t<=k then
    begin
      c:=a[t];
      a[t]:=a[k];
      a[k]:=c;
      inc(t);
      dec(k);
    end;
until t>k;
if t<r then qsorta(t,r);
if k>l then qsorta(l,k);
end;
procedure qsortb(l,r:longint);
var t,k:longint;
    i,c:int64;
begin
t:=l;
k:=r;
i:=b[(l+r)div 2];
repeat
  while b[t]<i do inc(t);
  while b[k]>i do dec(k);
  if t<=k then
    begin
      c:=b[t];
      b[t]:=b[k];
      b[k]:=c;
      inc(t);
      dec(k);
    end;
until t>k;
if t<r then qsortb(t,r);
if k>l then qsortb(l,k);
end;
begin
assign(input,'cut.in');
reset(input);
assign(output,'cut.out');
rewrite(output);
readln(n,m);
for t:=1 to n-1 do
  read(a[t]);
for t:=1 to m-1 do
  read(b[t]);
qsorta(1,n-1);
qsortb(1,m-1);
i:=n-1;
j:=m-1;
repeat
  if a[i]>b[j] then
    begin
      an:=an+a[i];
      dec(i);
      for t:=0 to j do
        b[t]:=(b[t]div(n-1-i))*(n-i);
    end
  else if a[i]<b[j] then
    begin
      an:=an+b[j];
      dec(j);
      for t:=0 to i do
        a[t]:=(a[t] div (m-1-j))*(m-j);
    end
  else if i<j then
    begin
      an:=an+b[j];
      dec(j);
      for t:=1 to i do
        a[t]:=(a[t] div (m-1-j))*(m-j);
    end
  else
    begin
      an:=an+a[i];
      dec(i);
      for t:=0 to j do
        b[t]:=(b[t]div(n-1-i))*(n-i);
    end;
until (i=0)and(j=0);
writeln(an);
close(output);
end.