fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, A[1000001], B[1000001];
  4. int main() {
  5. cin >> n;
  6. for (int i = 1; i <= n; i++) cin >> A[i];
  7. for (int i = 1; i <= n; i++) cin >> B[i];
  8. sort(A + 1, A + n + 1);
  9. sort(B + 1, B + n + 1);
  10. int k = 2e9;
  11. for (int i = 1, j = n; i <= n; i++) {
  12. while (j > 0 && A[i] + B[j] > 0) k = min(k, A[i] + B[j]), j--;
  13. if (j > 0) k = min(k, -(A[i] + B[j]));
  14. }
  15. cout << k;
  16. return 0;
  17. }
Success #stdin #stdout 0s 5560KB
stdin
6
3 5 -3 1 7 9
2 1 4 6 9 -6
stdout
1