Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals), problem: (D) Office Keys Solution In C/C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e3+5;
int main(){
int n,k,p,a[maxn],b[maxn];
int res=INT_MAX,i,j;
cin>>n>>k>>p;
for(i=0;i<n;i++) scanf(“%d”,a+i);
for(i=0;i<k;i++) scanf(“%d”,b+i);
sort(a,a+n);
sort(b,b+k);
for(i=0;i<=k-n;i++){
int t=0;
for(j=0;j<n;j++) t=max(t,abs(a[j]-b[i+j])+abs(p-b[i+j]));
res=min(t,res);
}
cout<<res;

return 0;
}

(Visited 15 times, 1 visits today)

About the Author:

Leave A Comment