QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100

#21348. 牛を追う

统计

Farmer John が柵の穴を直し忘れ、$N$ 頭 $(1 \le N \le 1,000)$ が逃げて暴れました!柵の外にいる間、各牛は毎分一ドルの損害を出します。FJ は全てを訪ねて無口を付け、落ち着かせ損害を止めます。

牛は農場外の直線の道路の相異なる位置にいます。FJ は各牛 $i$ の位置 $P_i$ $(-500,000 \le P_i \le 500,000, P_i \ne 0)$ を、出発する門(位置 $0$)を基準に知っています。

毎分一単位進み、無口は瞬時に付けられます。総損害を最小にする訪問順を考え、その最小値を計算してください。

入力

  • $1$ 行目:牛の数 $N$。

  • $2..N+1$ 行目:$i+1$ 行目に整数 $P_i$。

出力

  • $1$ 行目:最小総損害。

入出力例

入力 1

4
-2
-12
3
7

出力 1

50

注記

四頭の位置は $-2$、$-12$、$3$、$7$ です。

最適順は $-2$、$3$、$7$、$-12$。$-2$ に $2$ 分で着き、この牛の損害は $2$ ドルです。

$3$ まで距離 $5$ を進み、その牛の累積損害は $2 + 5 = 7$ ドルです。

さらに $4$ 分で $7$ に着き、その牛は $7 + 4 = 11$ ドルです。

最後に $19$ 分で $-12$ へ行き、$11 + 19 = 30$ ドルです。

合計は $2 + 7 + 11 + 30 = 50$ ドルです。

問題作成者:Chris Tzamos、2006

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.