| 比赛 | 
    10101115 | 
    评测结果 | 
    AAAAAAATTT | 
    | 题目名称 | 
    矩形分割 | 
    最终得分 | 
    70 | 
    | 用户昵称 | 
    1102 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    Pascal | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-15 09:37:49 | 
显示代码纯文本
program xxxx;
var j,n,m,s:longint;
    a:array[1..2000,1..2000] of longint;
procedure cut(x1,y1,x2,y2:longint);
var i,w,w1,w2:longint;
begin
  if (x2-x1>0)or(y2-y1>0) then
    begin
      w:=0;
      for i:=x1 to x2-1 do
        if a[i,1]>w then
          begin
            w:=a[i,1];
            w1:=i;
            w2:=1;
          end;
      for i:=y1 to y2-1 do
        if a[i,2]>w then
          begin
            w:=a[i,2];
            w1:=i;
            w2:=2;
          end;
      if w2=1 then
        begin
          s:=s+a[w1,w2];
          cut(x1,y1,w1,y2);
          cut(w1+1,y1,x2,y2);
        end
      else
        begin
          s:=s+a[w1,w2];
          cut(x1,y1,x2,w1);
          cut(x1,w1+1,x2,y2);
        end;
    end;
end;
begin
  assign(input,'cut.in');
  reset(input);
  assign(output,'cut.out');
  rewrite(output);
  read(n,m);
  s:=0;
  for j:=1 to n-1 do
    read(a[j,1]);
  for j:=1 to m-1 do
    read(a[j,2]);
  cut(1,1,n,m);
  write(s);
  close(input);
  close(output);
end.