問題一覧 > 通常問題

No.2315 Flying Camera

レベル : / AI推定難易度 : 167 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 208
作問者 : 👑 amentorimaru / テスター : tatyam cleantted
お気に入りにしたユーザー ProblemId : 9209 / 自分の提出
問題文最終更新日: 2023-05-26 18:52:45
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 390 (順位表) の他の問題:

Problem Statement

In a virtual space, $N$ Etowanyu-kun are scattered across $2$-dimensional coordinates. How cute.


Positions in this virtual space are represented by $2$-dimensional Cartesian coordinates, and the $i$-th Etowanyu-kun is at coordinates $(X_i,Y_i)$.

You can fly a drone camera and take a photo with the focus set on any lattice point in the $2$-dimensional coordinates.

Let $S$ be the sum of "the Manhattan distance from each Etowanyu-kun to the lattice point in focus".
That is, if the coordinates in focus are $(x, y)$, then $S = \displaystyle\sum_{i=1}^N\left(|X_i - x| + |Y_i - y|\right)$.

You want to choose a place from which all the Etowanyu-kun can be photographed well, so find the minimum value of $S$.

Input

$N$
$X_1 \ Y_1$
$X_2 \ Y_2$
$\vdots$
$X_N \ Y_N$
  • All inputs are integers.
  • $1 \le N \le 300$
  • $1 \le X_i, \ Y_i \le 300$

Output

Output the minimum value of $S$, followed by a newline.

Sample

Sample 1
Input
4
2 5
1 4
5 2
4 1
Output
12

By setting the focus on $(3,3)$:

The distance from the $1$st Etowanyu-kun is $|3-2|+|3-5|=3$.

The distance from the $2$nd Etowanyu-kun is $|3-1|+|3-4|=3$.

The distance from the $3$rd Etowanyu-kun is $|3-5|+|3-2|=3$.

The distance from the $4$th Etowanyu-kun is $|3-4|+|3-1|=3$.

This gives $S=12$, which is the minimum, so output this value.

Focusing on $(4,4)$ also gives $S=12$.

Sample 2
Input
3
100 100
100 100
100 100
Output
0

All the Etowanyu-kun are at the same place, so by setting the focus on that same place you get $S=0$ and can enjoy a fluffy photo shoot.

Sample 3
Input
8
12 18
5 11
30 5
19 19
23 15
6 6
2 28
2 12
Output
115

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。