No.1874 Minimum of Sum of Rectangles
タグ : / 解いたユーザー数 13
作問者 :
shiomusubi496
/ テスター :
ぷら
Problem Statement
For $2$ points $P,Q$ on the $xy$ plane, we define $rect(P,Q)$ as follows.
\[rect(P,Q) := \begin{cases} \text{すべての辺が}\ x\ \text{軸または}\ y\ \text{軸と平行であり、}\ P\ \text{と}\ Q\ \text{を頂点として持つ長方形の面積} & (P\ \text{と}\ Q\ \text{の}\ x\ \text{座標と}\ y\ \text{座標がともに異なる場合}) \\ 0 & (\text{それ以外の場合}) \\ \end{cases} \] In the formula above, the value is the area of the rectangle whose sides are all parallel to the x-axis or the y-axis and which has P and Q as vertices if P and Q differ in both their x-coordinates and their y-coordinates, and 0 otherwise.
You are given an integer $N$ and $N$ points $P_1(X_1, Y_1), P_2(X_2, Y_2), \dots, P_N(X_N, Y_N)$ on the $xy$ plane. For a point $Q$, we define $f(Q)$ as follows.
\[ f(Q) := \displaystyle \sum_{i=1}^N rect(P_i, Q) \]
Find the minimum value of $f(Q)$ when the point $Q$ is chosen appropriately.
Input
$N$ $X_1$ $Y_1$ $X_2$ $Y_2$ $\vdots$ $X_N$ $Y_N$
- $1 \leq N \leq 10^5$
- $0 \leq X_i, Y_i \leq 10^6$ $(1 \leq i \leq N)$
- All input values are integers.
Output
Output the answer. It can be proved that the answer is an integer under the constraints of this problem. (Added at 21:58)
Sample
Sample 1
Input
3 0 0 1 1 2 2
Output
1
For example, if $Q = (0, 2)$, then $f(Q) = 0 + 1 + 0 = 1$. This is the minimum, so output $1$.
Sample 2
Input
2 10 10 10 10
Output
0
If $Q = (10, 10)$, then $f(Q) = 0$.
Sample 3
Input
10 58 74 60 3 83 30 51 85 25 70 82 62 47 8 25 28 77 93 3 69
Output
3876
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。