Guest User

Untitled

a guest
Jul 13th, 2017
287
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int n,k;
  5. const int maxi=1e6;
  6. long long a[maxi],b[maxi],cnt[maxi];
  7. long long p;
  8. int main()
  9. {
  10.  
  11. cin>>n>>k>>p;
  12.  
  13.  
  14. for (int i=0;i<n;i++)
  15. scanf("%lld",&a[i]);
  16.  
  17. for (int j=0;j<k;j++)
  18. scanf("%lld",&b[j]);
  19.  
  20.  
  21. long long l=0;
  22. long long r=1e10;
  23. sort(a,a+n);
  24. sort(b,b+k);
  25.  
  26. while(l<r-1)
  27. {
  28. long long tr=(l+r)/2;
  29.  
  30. for (int i=0;i<k;i++)
  31. cnt[i]=0;
  32. int tot=0;
  33. for (int i=0;i<n;i++) {
  34. int oz=0;
  35. for (int j=0;j<k;j++)
  36. if (cnt[j]==0 && abs(b[j]-a[i])+abs(p-b[j])<=tr && !oz)
  37. {
  38. cnt[j]=1;
  39. tot++;
  40. oz=1;
  41. }
  42. }
  43. if (tot==n) r=tr; else l=tr;
  44. }
  45.  
  46. cout<<r;
  47. return 0;
  48. }
  49. //No Pistolero no fun
  50. //
RAW Paste Data