luogu#P3142. [USACO16OPEN] Field Reduction S

[USACO16OPEN] Field Reduction S

题目描述

Farmer John's NN cows (5N50,0005 \leq N \leq 50,000) are all located at distinct positions in his two-dimensional field. FJ wants to enclose all of the cows with a rectangular fence whose sides are parallel to the x and y axes, and he wants this fence to be as small as possible so that it contains every cow (cows on the boundary are allowed).

FJ is unfortunately on a tight budget due to low milk production last quarter. He would therefore like to build an even smaller fenced enclosure if possible, and he is willing to sell up to three cows from his herd to make this possible.

Please help FJ compute the smallest possible area he can enclose with his fence after removing up to three cows from his herd (and thereafter building the tightest enclosing fence for the remaining cows).

For this problem, please treat cows as points and the fence as a collection of four line segments (i.e., don't think of the cows as "unit squares"). Note that the answer can be zero, for example if all remaining cows end up standing in a common vertical or horizontal line.

输入格式

The first line of input contains NN. The next NN lines each contain two integers specifying the location of a cow. Cow locations are positive integers in the range 140,0001 \ldots 40,000.

输出格式

Write a single integer specifying the minimum area FJ can enclose with his fence after removing up to three carefully-chosen cows from his herd.

题目大意

题目描述

Farmer John 的 NN 头奶牛(5N50,0005 \leq N \leq 50,000)都位于他二维牧场中的不同位置。FJ 希望用一个边平行于 xx 轴和 yy 轴的矩形围栏围住所有的奶牛,并且他希望这个围栏尽可能小,以便能够包含每头奶牛(允许奶牛位于边界上)。

不幸的是,由于上个季度牛奶产量低,FJ 的预算非常紧张。因此,他希望如果可能的话,建造一个更小的围栏,并且他愿意从他的牛群中出售最多三头奶牛来实现这一目标。

请帮助 FJ 计算在从他的牛群中移除最多三头奶牛后,他可以用围栏围住的最小可能面积(然后为剩余的奶牛建造最紧密的围栏)。

对于这个问题,请将奶牛视为点,将围栏视为四条线段的集合(即不要将奶牛视为“单位正方形”)。请注意,答案可能为零,例如如果所有剩余的奶牛最终站在一条共同的垂直线或水平线上。

输入格式

输入的第一行包含 NN。接下来的 NN 行每行包含两个整数,表示一头奶牛的位置。奶牛的位置是范围在 140,0001 \ldots 40,000 的正整数。

输出格式

输出一个整数,表示 FJ 在从他的牛群中精心选择移除最多三头奶牛后,可以用围栏围住的最小面积。

6
1 1
7 8
10 9
8 12
4 100
50 7
12