問題一覧 > 通常問題

No.703 Garbage Collection Easy

レベル : / AI推定難易度 : 1900 / 実行時間制限 : 1ケース 1.500秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 92
作問者 : はむこ / テスター : 夕叢霧香(ゆうむらきりか)
お気に入りにしたユーザー ProblemId : 1948 / 自分の提出
問題文最終更新日: 2026-06-25 10:54:58
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 193 (順位表) の他の問題:

Problem Statement

There are $n$ pieces of garbage in a park.
A group of $n$ neighborhood volunteers is going to collect them.

Person $i (0 \le i < n)$ is initially at $(a_i, 0)$. Garbage $j (0 \le j < n)$ is initially at $(x_j, y_j)$.
Initially, person $i$ and garbage $j$ are sorted along the x-axis ($a_0 \le a_1 \le \cdots \le a_{n-1}$, $x_0 \le x_1 \le \cdots \le x_{n-1}$).

The effort for person $i$ to collect all of garbage $j$, garbage $j+1$, ..., garbage $i (0 \le j \le i)$ is the squared Euclidean distance between garbage $j$ and person $i$.
Person $i$ cannot collect garbage $j > i$. If person $i$ does not collect any garbage, that person's effort is $0$.

Minimize the total effort required to collect all the garbage.

Input

n
a_0 a_1 ... a_{n-1}
x_0 x_1 ... x_{n-1}
y_0 y_1 ... y_{n-1}

$1 \le n \le 3\times 10^5$
$0 \le a_i, x_i, y_i \le 10^5 (0 \le i < n)$
$a_0 \le a_1 \le \cdots \le a_{n-1}$
$x_0 \le x_1 \le \cdots \le x_{n-1}$

Output

The answer may not fit in a 32bit integer.
Print a newline at the end.

Sample

Sample 1
Input
4
0 1 2 3
0 1 2 3
1 1 1 1
Output
4

It is optimal for person $i$ to collect garbage $i$.
The vector from each person to their garbage is (0, 1), so the effort, the squared Euclidean distance, is 1. This effort applies to 4 people, so the answer is 4.

Sample 2
Input
4
0 1 2 3
0 1 2 3
10 10 10 10
Output
109

It is optimal for person $3$ to collect all the garbage. Persons $0, 1, 2$ are idle.
Since person $3$ takes garbage $[0, 3]$, the effort is the squared Euclidean distance between person $3$ and garbage $0$. Person 3 is at $(3, 0)$ and garbage $0$ is at $(0, 10)$, so the effort is $109=(3-0)^2+(0-10)^2$.

Sample 3
Input
4
0 1 2 3
0 1 2 3
2 2 2 2
Output
10

It is optimal for person $1$ to collect garbage $0, 1$ and for person $3$ to collect garbage $2, 3$. Persons $0, 2$ are idle.

Sample 3
Input
10
3251 5690 6665 16359 20099 34165 44782 58006 70432 72049 
2772 9289 40088 44279 57294 57580 57685 61437 68039 73446 
64849 45751 58453 17408 55499 38832 58870 71951 66081 4577 
Output
5230466661

The answer may not fit in a 32bit integer.

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