https://i0.wp.com/eblogarithm.com/wp-content/uploads/2017/07/Codeforces-Round-424-Div-2-rated-based-on-VK-Cup-Finals-problem-D-Office-Keys-Solution-In-CC1.png?fit=640%2C360

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 5 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: