Flags

AtCoder
IDarc069_d
Time5000ms
Memory256MB
Difficulty
Snuke loves flags. Snuke is placing $N$ flags on a line. The $i$\-th flag can be placed at either coordinate $x_i$ or coordinate $y_i$. Snuke thinks that the flags look nicer when the smallest distance between two of them, $d$, is larger. Find the maximum possible value of $d$. ## Constraints * $2 ≤ N ≤ 10^{4}$ * $1 ≤ x_i, y_i ≤ 10^{9}$ * $x_i$ and $y_i$ are integers. ## Input The input is given from Standard Input in the following format: $N$ $x_1$ $y_1$ $:$ $x_N$ $y_N$ [samples]
Samples
Input #1
3
1 3
2 5
1 9
Output #1
4

The optimal solution is to place the first flag at coordinate $1$, the second flag at coordinate $5$ and the third flag at coordinate $9$. The smallest distance between two of the flags is $4$ in this case.
Input #2
5
2 2
2 2
2 2
2 2
2 2
Output #2
0

There can be more than one flag at the same position.
Input #3
22
93 6440
78 6647
862 11
8306 9689
798 99
801 521
188 206
6079 971
4559 209
50 94
92 6270
5403 560
803 83
1855 99
42 504
75 484
629 11
92 122
3359 37
28 16
648 14
11 269
Output #3
17
API Response (JSON)
{
  "problem": {
    "name": "Flags",
    "description": {
      "content": "Snuke loves flags. Snuke is placing $N$ flags on a line. The $i$\\-th flag can be placed at either coordinate $x_i$ or coordinate $y_i$. Snuke thinks that the flags look nicer when the smallest distanc",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc069_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Snuke loves flags.\nSnuke is placing $N$ flags on a line.\nThe $i$\\-th flag can be placed at either coordinate $x_i$ or coordinate $y_i$.\nSnuke thinks that the flags look nicer when the smallest distanc...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments