| 记录编号 | 
        21776 | 
        评测结果 | 
        AAAAAAAAAA | 
    
    
        | 题目名称 | 
        498.矩形分割 | 
        最终得分 | 
        100 | 
            
    
    
        | 用户昵称 | 
         belong.zmx | 
        是否通过 | 
        通过 | 
    
    
        | 代码语言 | 
        Pascal | 
        运行时间 | 
        0.006 s  | 
    
    
        | 提交时间 | 
        2010-11-15 14:09:26 | 
        内存使用 | 
        0.19 MiB  | 
        
    
    
    
    		显示代码纯文本
		
		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 read(a[i]);
 readln;
 for i:=1 to m-1 do read(b[i]);
 readln;
 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.