证明:这里
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<queue>
#include<list>
#include<stack>
#include<bitset>
#include<cmath>
#include<map>
#include<functional>
#define int long long
#define IO ios::sync_with_stdio(false)
using namespace std;
int n,m;
int h[200005],w[200005],pre[200005],suf[200005];
signed main()
{
IO;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>h[i];
}
for(int i=1;i<=m;i++)
{
cin>>w[i];
}
sort(h+1,h+n+1);
for(int i=2;i<=n;i+=2)
{
pre[i]=pre[i-2]+abs(h[i]-h[i-1]);
}
for(int i=n-1;i>=1;i-=2)
{
suf[i]=suf[i+2]+abs(h[i]-h[i+1]);
}
int ans=1e9+7;
for(int i=1;i<=m;i++)
{
int pos=lower_bound(h+1,h+n+1,w[i])-h;
if(pos%2==0)pos--;
ans=min(ans,pre[pos-1]+suf[pos+1]+abs(h[pos]-w[i]));
}
cout<<ans;
}