比赛 10101115 评测结果 AAAAAAAAAA
题目名称 矩形分割 最终得分 100
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-15 08:45:23
显示代码纯文本
program zzn;
var
        i,j,m,n,ans,sn,sm:longint;
        cm,cn:array[1..2000]of longint;
procedure swap(var a,b:longint);
var
        t:longint;
begin
        t:=a;
        a:=b;
        b:=t;
end;
procedure init;
begin
        assign(input,'cut.in');
        reset(input);
        assign(output,'cut.out');
        rewrite(output);
        readln(n,m);
        for i:=1 to n-1 do read(cn[i]);readln;
        for i:=1 to m-1 do read(cm[i]);
        for i:=1 to n-1 do
         for j:=i+1 to n do if cn[i]<cn[j] then swap(cn[i],cn[j]);
        for i:=1 to m-1 do
         for j:=i+1 to m do if cm[i]<cm[j] then swap(cm[i],cm[j]);
end;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure main;
begin
        sn:=1;sm:=1;
        ans:=0;
        while true do
        begin
            if sn=n then
             begin
                 for i:=sm to m-1 do
                 ans:=ans+cm[i]*sn;
                 break;
             end;
            if sm=m then
             begin
                 for i:=sn to n-1 do
                  ans:=ans+cn[i]*sm;
                 break;
             end;
        if cm[sm]>cn[sn] then
         begin
             ans:=ans+cm[sm]*sn;
             inc(sm);
         end else
         begin
             ans:=ans+cn[sn]*sm;
             inc(sn);
         end;
        end;
         writeln(ans);
end;
begin
        init;
        main;
        closef;
end.