#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int i,j;
int a[n],b[m],c[m+n];
for(i=0;i<n;i++) {scanf("%d",&a[i]);c[i]=a[i];}
for(j=0;j<m;j++) {scanf("%d",&b[j]);c[n+j]=b[j];}
sort(c,c+m+n);
int t=c[m];
long long ans=0;
for(i=0;i<n;i++)
{
if(a[i]<t)
{
ans+=t-a[i];
}
}
for(j=0;j<m;j++)
{
if(b[j]>t)
{
ans+=b[j]-t;
}
}
printf("%I64d\n",ans);
return 0;
}
老板的三分~~~~
/**
* @author neko01
*/
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define clr(a) memset(a,0,sizeof a)
#define clr1(a) memset(a,-1,sizeof a)
#define dbg(a) printf("%d\n",a)
typedef pair<int,int> pp;
#define INF 0x7fffffff
const LL inf=(((LL)1)<<61)+5;
LL a[100005];
LL b[100005];
int n,m;
LL gao(LL mid)
{
LL gao1=0,gao2=0,ans=0;
for(int i=0;i<n;i++)
{
if(a[i]<mid)
gao1+=(mid-a[i]);
}
for(int i=0;i<m;i++)
{
if(b[i]>mid)
gao2+=(b[i]-mid);
}
ans=gao1+gao2;
return ans;
}
int main()
{
scanf("%d%d",&n,&m);
LL mmin=INF,mmax=0;
for(int i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
mmin=min(mmin,a[i]);
}
for(int i=0;i<m;i++)
{
scanf("%I64d",&b[i]);
mmax=max(mmax,b[i]);
}
if(mmax<mmin)
{
printf("0\n");
return 0;
}
LL l=0,r=INF;
LL ans=inf;
while(l<=r)
{
LL mid=(l+r)>>1;
LL midmid=(mid+r)>>1;
LL gao1=gao(mid);
LL gao2=gao(midmid);
//printf("%d %d\n",gao1,gao2);
if(gao1<gao2)
r=midmid-1,ans=min(ans,gao1);
else
l=mid+1,ans=min(ans,gao2);
}
printf("%I64d\n",ans);
return 0;
}