比赛 |
10101115 |
评测结果 |
AWWWWWWWWW |
题目名称 |
矩形分割 |
最终得分 |
10 |
用户昵称 |
belong.zmx |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2010-11-15 08:16:07 |
显示代码纯文本
program cut(input,output);
var
i,j:longint;
n,m:longint;
ans,nn,mm:longint;
a,b:array[0..10000]of longint;
procedure sort1(x,y:longint);
var
i,j:longint;
k,p:longint;
begin
k:=a[(x+y)div 2];
i:=x;
j:=y;
repeat
while a[i]<k do inc(i);
while a[j]>k do dec(j);
if i<=j then
begin
p:=a[i];
a[i]:=a[j];
a[j]:=p;
inc(i);
dec(j);
end;
until i>j;
if i<y then sort1(i,y);
if x<j then sort1(x,j);
end;
procedure sort2(x,y:longint);
var
i,j:longint;
k,p:longint;
begin
k:=b[(x+y)div 2];
i:=x;
j:=y;
repeat
while b[i]<k do inc(i);
while b[j]>k do dec(j);
if i<=j then
begin
p:=b[i];
b[i]:=b[j];
b[j]:=p;
inc(i);
dec(j);
end;
until i>j;
if i<y then sort2(i,y);
if x<j then sort2(x,j);
end;
begin
assign(input,'cut.in');
reset(input);
readln(n,m);
for i:=1 to n-1 do readln(a[i]);
for i:=1 to m-1 do readln(b[i]);
close(input);
sort1(1,n-1);
sort2(1,m-1);
nn:=n-1;
mm:=m-1;
while (mm>0)or(nn>0) do
begin
if a[nn]>b[mm] then
begin
ans:=ans+(m-1-mm+1)*a[nn];
dec(nn);
end
else
begin
ans:=ans+(n-1-nn+1)*b[mm];
dec(mm);
end;
end;
assign(output,'cut.out');
rewrite(output);
writeln(ans);
close(output);
end.