Codeforces Round #424 (Div. 2 Archive

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

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,b; 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-b)+abs(p-b)); res=min(t,res); } cout<<res; return 0; }