{矩形分割
贪心算法
Author: yangbohua
Time: 2010-11-15 09:13}
program cut;
var
a:array[1..4000] of longint;
b:array[1..4000] of integer;
n,m,i,x,y,ans:longint;
procedure sort(l,r:longint);
var
i,j,mid,temp:longint;
begin
i:=l;
j:=r;
mid:=a[(l+r) div 2];
repeat
while a[i]>mid do
inc(i);
while mid>a[j] do
dec(j);
if not(i>j) then
begin
temp:=a[i]; a[i]:=a[j]; a[j]:=temp;
temp:=b[i]; b[i]:=b[j]; b[j]:=temp;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
assign(input,'cut.in');
reset(input);
assign(output,'cut.out');
rewrite(output);
readln(n,m);
for i:=1 to n+m-2 do
begin
read(a[i]);
if i<=n-1
then b[i]:=1
else b[i]:=2;
end;
sort(1,n+m-2);
x:=1;
y:=1;
for i:=1 to n+m-2 do
begin
if b[i]=1 then
begin
ans:=ans+a[i]*y;
x:=x+1;
end
else
begin
ans:=ans+a[i]*x;
y:=y+1;
end;
end;
writeln(ans);
close(input);
close(output)
end.