比赛 10101115 评测结果 AAAAAAEEEE
题目名称 矩形分割 最终得分 60
用户昵称 sr-end 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 10:19:59
显示代码纯文本
program aaa;
type c=array[0..2002] of longint;
var n,m,i,j:longint;
    a,b:c;
    f:array[0..100,0..100] of longint;
     f1: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(f1,'cut.in');
reset(f1);
  readln(f1,n,m);
  for i:=1 to n-1 do
  read(f1,a[i]);
   readln(f1);
  for i:=1 to m-1 do
  read(f1,b[i]);
  readln(f1);
  assign(f1,'cut.out');
  rewrite(f1);
  randomize;
  sort(1,n-1,a);
  sort(1,m-1,b);
  for i:=1 to n-1 do f[i,0]:=f[i-1,0]+a[i];
  for i:=1 to m-1 do f[0,i]:=f[0,i-1]+b[i];
  for i:=1 to n-1 do
    for j:=1 to m-1 do
      f[i,j]:=min(f[i-1,j]+a[i]*(j+1),f[i,j-1]+b[j]*(i+1));
  writeln(f1,f[n-1,m-1]);
  close(f1);
end.