思路:

  背包;

代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 1005
#define maxk 2005
#define ll long long
int n,k,p;
ll dp[maxn][maxk],ai[maxn],bi[maxk];
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void in(ll &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline ll check()
{
//memset(dp,127/3,sizeof(dp));
for(int i=;i<=n;i++)
for(int v=;v<=k;v++)
dp[i][v]=max(dp[i-][v-],abs(ai[i]-bi[v])+abs(bi[v]-p));
ll Min=2e9;
for(int i=n;i<=k;i++) Min=min(dp[n][i],Min);
return Min;
}
int main()
{
in(n),in(k),in(p);
for(int i=;i<=n;i++) in(ai[i]);
for(int i=;i<=k;i++) in(bi[i]);
sort(ai+,ai+n+),sort(bi+,bi+k+);
cout<<check();
return ;
}
05-28 21:26