fork download
  1. #include <bits/stdc++.h>
  2. #define MOD 1000000007
  3. #define Tran_Hoan_Thien ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  4. #define fi first
  5. #define se second
  6. #define pb push_back
  7. #define vi vector<int>
  8. #define ll long long
  9. #define vll vector<ll>
  10. #define db double
  11. #define pii pair<int,int>
  12. #define endl "\n"
  13. #define str string
  14. #define pk pop_back
  15. #define LB lower_bound
  16. #define UB upper_bound
  17. #define all(a) a.begin(),a.end()
  18. #define sz(a) int((a).size())
  19. #define rv(a) a.rbegin(),a.rend()
  20. using namespace std;
  21. ll gcd(ll a,ll b){return __gcd(a,b);}
  22. ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
  23. int main(){
  24. #define TASK ""
  25. if(fopen(TASK ".inp", "r")){
  26. freopen(TASK ".inp", "r", stdin);
  27. freopen(TASK ".out", "w", stdout);
  28. }
  29. freopen("NKSGAME.INP ", "r", stdin);
  30. freopen("NKSGAME.OUT", "w", stdout);
  31. Tran_Hoan_Thien;
  32. int n;cin>>n;
  33. vi a(n),b(n);
  34. for(int &x:a) cin>>x;
  35. for(int &x:b) cin>>x;
  36. sort(all(b));
  37. ll res=LLONG_MAX;
  38. for(int i=0;i<n;i++){
  39. int tmp=-b[i];
  40. auto it=lower_bound(all(b),tmp);
  41. if(it!=b.end()) res=min(res,abs(1ll*a[i]+*it));
  42. if(it!=b.begin()){
  43. it--;
  44. res=min(res, abs(1LL * a[i] + *it));
  45. }
  46. }
  47. cout << res;
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty