問題一覧 > 通常問題

No.3066 Collecting Coins Speedrun 1

レベル : / AI推定難易度 : 159 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 138
作問者 : 👑 AngrySadEight / テスター : aplysiaSheep 👑 hamamu
お気に入りにしたユーザー ProblemId : 11897 / 自分の提出
問題文最終更新日: 2025-02-18 18:43:22
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 461 (順位表) の他の問題:

Problem Statement

There are $N$ coins on a number line. The $i$-th coin is at coordinate $c_i$. The coordinates of any $2$ coins are distinct from each other.

You are initially at coordinate $0$. You may move a distance of $1$ in the positive or negative direction any number of times.

You can obtain a coin if and only if you are at the same coordinate as that coin.

Your goal is to collect all the coins and finally return to coordinate $0$. Find the minimum total distance traveled required to achieve the goal.

Constraints

  • All inputs are integers
  • $1 \leq N \leq 10^5$
  • $-10^8 \leq c_1 < c_2 < \dots < c_N \leq 10^8$

Input

The input is given from standard input in the following format.

$N$
$c_1$ $c_2$ $\dots$ $c_N$

Output

Output the answer.

Sample

Sample 1
Input
3
-1 1 3
Output
8

By collecting the coins in the order of the $1$-st, $3$-rd, and $2$-nd, you move through the coordinates as $0 \rightarrow -1 \rightarrow 3 \rightarrow 1 \rightarrow 0$, so the total distance traveled is $1 + 4 + 2 + 1 = 8$.

Note that you must return to coordinate $0$ after collecting all the coins.

Sample 2
Input
9
-31415296 -26457513 -24494897 -17320508 -14142135 0 22360679 27182818 31622776
Output
126076144

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