记录编号 |
21892 |
评测结果 |
AAAAAAAAAA |
题目名称 |
矩形分割 |
最终得分 |
100 |
用户昵称 |
itachi |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.006 s |
提交时间 |
2010-11-15 19:28:02 |
内存使用 |
0.13 MiB |
显示代码纯文本
program p1(input,output);
var
d1,d2:array[1..2000]of longint;
h1,h2,t1,t2,i,n,m:integer; max:longint;
procedure qsort1(l,r:integer);
var
i,j:integer;x,y:longint;
begin
i:=l;j:=r;
x:=d1[(l+r) div 2 ];
repeat
while d1[i]>x do inc(i);
while d1[j]<x do dec(j);
if i<=j then
begin
y:=d1[i];
d1[i]:=d1[j];
d1[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if j>l then qsort1(l,j);
if i<r then qsort1(i,r);
end;
procedure qsort2(l,r:integer);
var
i,j:integer;x,y:longint;
begin
i:=l;j:=r;
x:=d2[(l+r) div 2 ];
repeat
while d2[i]>x do inc(i);
while d2[j]<x do dec(j);
if i<=j then
begin
y:=d2[i];
d2[i]:=d2[j];
d2[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if j>l then qsort2(l,j);
if i<r then qsort2(i,r);
end;
procedure main;
begin
assign(input,'cut.in');
reset(input);
assign(output,'cut.out');
rewrite(output);
readln(n,m);
for i:= 1 to n-1 do
read(d1[i]);
h1:=1;
t1:=n-1;
for i:= 1 to m-1 do
read(d2[i]);
h2:=1;
t2:=m-1;
close(input);
qsort1(1,t1);
qsort2(1,t2);
max:=0;
while (h1<=t1 )or (h2<=t2) do
begin
if( (d1[h1]> d2[h2])and(h1<=t1)) or((h1<=t1)and(h2>t2) ) then
begin
inc(max,d1[h1]*h2);
inc(h1);
end
else
if( h2<=t2) or( (h1>t1)and(h2<=t2)) then
begin
inc(max,d2[h2]*h1);
inc(h2);
end;
end;
writeln(max);
close(output);
end;
begin
main;
end.