记录编号 |
21818 |
评测结果 |
AAAAAAAAAA |
题目名称 |
矩形分割 |
最终得分 |
100 |
用户昵称 |
magic |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.011 s |
提交时间 |
2010-11-15 16:45:39 |
内存使用 |
23.99 MiB |
显示代码纯文本
program gls;
var
m,n,i,j,k,heng,shu,min:longint;
a,b:array[0..2500]of longint;
ss:array[0..2500,0..2500]of longint;
f,g:text;
procedure Sorta(l, r: longint);
var
i, j, x, y,yy: longint;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] do j := j - 1;
if i <= j then
begin
y := a[i]; a[i] := a[j]; a[j] := y;
yy:= b[i]; b[i] := b[j]; b[j] :=yy;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sorta(l, j);
if i < r then Sorta(i, r);
end;
begin
assign(f,'cut.in');reset(f);
assign(g,'cut.out');rewrite(g);
readln(f,m,n);
for i:=1 to m-1 do begin read(f,a[i]);b[i]:=1; end;
for i:=m to m+n-2 do begin read(f,a[i]);b[i]:=2; end;
sorta(1,m+n-2);
heng:=1;
shu :=1;
for k:=m+n-2 downto 1 do
begin if b[k]=1 then begin inc(heng);min:=min+a[k]*shu;end;
if b[k]=2 then begin inc(shu);min:=min+a[k]*heng; end;
end;
writeln(g,min);
close(f);close(g);
end.