记录编号 |
21755 |
评测结果 |
AAAAAAAAAA |
题目名称 |
矩形分割 |
最终得分 |
100 |
用户昵称 |
maxiem |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.018 s |
提交时间 |
2010-11-15 11:52:07 |
内存使用 |
0.13 MiB |
显示代码纯文本
program cut;
var
data:array [0..2000,1..2] of longint;
i,np,mp,nm,mm,n,m:longint;
ans:int64;
procedure qsort(a,b,no:longint);
var
i,j,s,t:longint;
begin
if a<b then begin
i:=a;j:=b;
s:=data[a,no];
repeat
while (i<j) and (data[j,no]>=s) do dec(j);
if i<j then begin
data[i,no]:=data[j,no];
inc(i);
end;
while (i<j) and (data[i,no]<=s) do inc(i);
if i<j then begin
data[j,no]:=data[i,no];
dec(j);
end;
until i=j;
data[i,no]:=s;
qsort (a,j-1,no);
qsort (i+1,b,no);
end;
end;
begin
fillchar (data,sizeof(data),0);
assign (input,'cut.in');
reset (input);
readln (n,m);
for i:=1 to n-1 do read (data[i,1]);
readln;
for i:=1 to m-1 do read (data[i,2]);
qsort(1,n-1,1);
qsort(1,m-1,2);
close (input);
np:=1;mp:=1;
nm:=n-1;mm:=m-1;
ans:=0;
assign (output,'cut.out');
rewrite (output);
for i:=1 to n+m-2 do begin
if data[nm,1]>data[mm,2] then begin
ans:=ans+data[nm,1]*np;
inc(mp);
dec(nm);
end
else begin
ans:=ans+data[mm,2]*mp;
inc(np);
dec(mm);
end;
end;
writeln (ans);
close (output);
end.