QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 2048 MB مجموع النقاط: 100 قابلة للهجوم ✓

#14444. シーソー

الإحصائيات

無限に長いシーソーの上に何人かの人が座っています。このシーソーは、$0$ を中心とする数直線として表すことができます。各人には重さがあり、シーソー上の特定の位置に座っています。彼らは「重さ $\times$ 位置」に等しいトルクをシーソーに与えます。シーソーは、トルクの合計が $0$ になるときに釣り合います。

人々は、すぐ前またはすぐ後ろの人を追い越さない限り、シーソーに沿って任意の距離(実数値)だけ移動することができます。言い換えれば、シーソー上での人々の相対的な順序は維持されなければなりません。複数の人が同じ位置にいることや、一人が複数回移動することは許容されます。シーソーを釣り合わせるために、人々が移動しなければならない距離の合計の最小値はいくらでしょうか。

入力

入力の最初の行には、人数を表す整数 $n$ ($1 \le n \le 10^5$) が含まれます。

続く $n$ 行のそれぞれには、2つの整数 $p$ ($-10^8 \le p \le 10^8$) と $w$ ($1 \le w \le 10^5$) が含まれます。ここで $p$ はその人のシーソー上の位置、$w$ はその人の重さです。$p$ の値は一意であり、昇順に並んでいることが保証されています。

出力

シーソーを釣り合わせるために全員が移動した距離の合計の最小値を、単一の数値として出力してください。答えは、絶対誤差または相対誤差が $10^{-6}$ 以内であれば正解となります。

入出力例

入力 1

3
-3 4
3 1
5 1

出力 1

1.000000

入力 2

3
-2 1
1 4
2 4

出力 2

2.500000

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.