比赛 10101115 评测结果 EEEEEEEEEE
题目名称 矩形分割 最终得分 0
用户昵称 ZHZH 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 10:02:52
显示代码纯文本
program sample;
type c=array[0..2002] of longint;
var
 n,m,i,j:longint;
 a,b:c;
 d:array[0..2002,0..2002] of longint;
 f:text;

function min(x,y:longint):longint;
  begin
    if x<y then min:=x
           else min:=y;
  end;

procedure sort(p,q:longint; var a:c);
var
 l,r,o,x:longint;
 begin
  l:=p; r:=q;
  o:=a[l+random(r-l+1)];
  repeat
   while a[l]>o do inc(l);
   while o>a[r] do dec(r);
   if l<=r then begin
    x:=a[l];
    a[l]:=a[r];
    a[r]:=x;
    inc(l); dec(r);
   end;
   until l>r;
   if p<r then sort(p,r,a);
   if l<q then sort(l,q,a);
 end;

Begin
assign(f,'d:\\cut.in');
reset(f);
  readln(f,n,m);
  for i:=1 to n-1 do read(f,a[i]);
  readln(f);
  for i:=1 to m-1 do read(f,b[i]);
  readln(f);
  close(f);
  randomize;
  sort(1,n-1,a);
  sort(1,m-1,b);
  for i:=1 to n-1 do
   d[i,0]:=d[i-1,0]+a[i];
  for i:=1 to m-1 do
   d[0,i]:=d[0,i-1]+b[i];
  for i:=1 to n-1 do
    for j:=1 to m-1 do
      d[i,j]:=min(d[i-1,j]+a[i]*(j+1),d[i,j-1]+b[j]*(i+1));
assign(f,'d:\\cut.out');
rewrite(f);
writeln(f,d[n-1,m-1]);
close(f);
End.