E - Ball Coloring Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 700700

問題文

22 個の白いボールが入った袋が NN 個あります。ii 個目の袋にはそれぞれ整数 xix_iyiy_i が書かれたボールが 11 個ずつ入っています。

あなたはこの袋それぞれについて、片方のボールを赤く塗り、もう片方を青く塗ります。

そのあと 2N2N 個のボールを、塗られた色で分類します。

そして

  • 赤く塗られたボールに書かれた整数の最大値を RmaxR_{max}
  • 赤く塗られたボールに書かれた整数の最小値を RminR_{min}
  • 青く塗られたボールに書かれた整数の最大値を BmaxB_{max}
  • 青く塗られたボールに書かれた整数の最小値を BminB_{min}

としたときに、(RmaxRmin)×(BmaxBmin)(R_{max} - R_{min}) \times (B_{max} - B_{min}) の最小値を求めてください。

制約

  • 1N200,0001 ≦ N ≦ 200,000
  • 1xi,yi1091 ≦ x_i, y_i ≦ 10^9

入力

入力は以下の形式で標準入力から与えられる。

NN
x1x_1 y1y_1
x2x_2 y2y_2
:
xNx_N yNy_N

出力

問題の答えを出力する。


入力例 1Copy

Copy
3
1 2
3 4
5 6

出力例 1Copy

Copy
15

x1x_1, x2x_2, y3y_3 の書かれたボールを赤色に塗り、 y1y_1, y2y_2, x3x_3 の書かれたボールを青色に塗ると最適解になります。


入力例 2Copy

Copy
3
1010 10
1000 1
20 1020

出力例 2Copy

Copy
380

入力例 3Copy

Copy
2
1 1
1000000000 1000000000

出力例 3Copy

Copy
999999998000000001

Score : 700700 points

Problem Statement

There are NN bags, each containing two white balls. The ii-th box contains two balls with integers xix_i and yiy_i written on them, respectively.

For each of these bags, you will paint one of the balls red, and paint the other blue.

Afterwards, the 2N2N balls will be classified according to color.

Then, we will define the following:

  • RmaxR_{max}: the maximum integer written on a ball painted in red
  • RminR_{min}: the minimum integer written on a ball painted in red
  • BmaxB_{max}: the maximum integer written on a ball painted in blue
  • BminB_{min}: the minimum integer written on a ball painted in blue

Find the minimum possible value of (RmaxRmin)×(BmaxBmin)(R_{max} - R_{min}) \times (B_{max} - B_{min}).

Constraints

  • 1N200,0001 ≤ N ≤ 200,000
  • 1xi,yi1091 ≤ x_i, y_i ≤ 10^9

Input

Input is given from Standard Input in the following format:

NN
x1x_1 y1y_1
x2x_2 y2y_2
:
xNx_N yNy_N

Output

Print the minimum possible value.


Sample Input 1Copy

Copy
3
1 2
3 4
5 6

Sample Output 1Copy

Copy
15

The optimal solution is to paint the balls with x1x_1, x2x_2, y3y_3 red, and paint the balls with y1y_1, y2y_2, x3x_3 blue.


Sample Input 2Copy

Copy
3
1010 10
1000 1
20 1020

Sample Output 2Copy

Copy
380

Sample Input 3Copy

Copy
2
1 1
1000000000 1000000000

Sample Output 3Copy

Copy
999999998000000001


2025-04-14 (Mon)
10:35:45 +00:00