#include #include using namespace std; typedef pair P; int main() { int n; cin >> n; int a[200005], b[200005]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } set

st; for (int i = 0; i < n; i++) { if (a[i] > b[i]) { swap(a[i], b[i]); } st.insert(P(b[i], i)); } int ans = st.rbegin()->first - st.begin()->first; while (true) { P p = *st.rbegin(); st.erase(p); int i = p.second; if (p.first == a[i]) { break; } if (p.first == b[i]) { st.insert(P((a[i] + b[i]) / 2, i)); } else { st.insert(P(a[i], i)); } ans = min(ans, st.rbegin()->first - st.begin()->first); } cout << ans << endl; }