-----------
简单DP
d[i][j]=前i个人,使用前j条钥匙,都前往p,最慢的人需要的最短时间
d[i][j]=min{d[i][j−1],max(d[i−1][j−1],|a[i]−b[j]|+|p−b[j]|)}
O(n2)
#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) ((x)&-(x))
using namespace std;
const int inf=0x3f3f3f3f;
const int N = 2000+5;
int a[N],b[N];
ll d[N][N];
ll slove(int n,int k,int p){
MEM(d,0x3f);
fill(d[0],d[0]+k+1,0);
for(int i=1;i<=n;++i){
for(int j=1;j<=k;++j){
d[i][j]=min(d[i][j-1],max(d[i-1][j-1],(ll)abs(a[i]-b[j])+abs(b[j]-p)));
}
}
return d[n][k];
}
int main()
{
//freopen("/home/lu/code/r.txt","r",stdin);
int n,k,p;
while(~scanf("%d%d%d",&n,&k,&p)){
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
}
for(int i=1;i<=k;++i){
scanf("%d",&b[i]);
}
sort(a+1,a+n+1);
sort(b+1,b+k+1);
printf("%lld\n",slove(n,k,p));
}
return 0;
}