#P5804. Optimal Difference Game

    ID: 19032 Type: Default 1000ms 256MiB

Optimal Difference Game

Optimal Difference Game

Alice and Bob are playing a game with their own sequences of numbers. Alice has a sequence \(a\) consisting of \(n\) integers and Bob has a sequence \(b\) consisting of \(n\) integers. In each turn, the current player deletes exactly one number from his/her own sequence. Alice takes the first turn and they alternate turns. The game ends when both sequences are reduced to exactly one number. Let the remaining number in Alice's sequence be \(x\) and in Bob's sequence be \(y\).

Alice aims to maximize \(|x-y|\) (the absolute difference between \(x\) and \(y\)) while Bob aims to minimize \(|x-y|\). Both players play optimally. Determine the final result \(|x-y|\) when the game ends.

Game Analysis:
Since each player controls only his/her own sequence, the final outcome is determined by the choice of the remaining element in each sequence. Regardless of the play order, the outcome is equivalent to Alice choosing an element \(x\) from sequence \(a\) and Bob, knowing \(x\), choosing an element \(y\) from sequence \(b\) which minimizes \(|x-y|\). Therefore, the final value of \(|x-y|\) is:

[ \max_{x \in a} \left( \min_{y \in b} |x-y| \right) ]

Your task is to compute this value given the two sequences.

inputFormat

The first line contains an integer \(n\) (the size of each sequence).
The second line contains \(n\) integers representing the sequence \(a\).
The third line contains \(n\) integers representing the sequence \(b\).

You can assume that \(n \ge 1\) and the absolute values of the numbers do not exceed \(10^9\).

outputFormat

Output a single integer denoting the final value of \(|x-y|\) when both players play optimally.

sample

2
1 10
5 6
4

</p>