QOJ.ac

QOJ

时间限制: 2 s 内存限制: 2048 MB 总分: 100 可 Hack ✓

#14444. 蹺蹺板

统计

有一些人坐在一個無限長的蹺蹺板上。這個蹺蹺板可以表示為一個以 $0$ 為中心的數線。每個人都有一個重量,並坐在蹺蹺板上的某個位置。他們貢獻的力矩等於他們的重量乘以他們的位置。如果力矩總和為 $0$,則蹺蹺板達到平衡。

人們可以在蹺蹺板上移動任意實數距離,只要他們不越過他們前後的人即可。換句話說,必須保持人們在蹺蹺板上的相對順序。多個人佔據同一個位置是可以的,一個人也可以移動多次。為了使蹺蹺板平衡,人們必須移動的總距離之最小值是多少?

輸入格式

第一行包含一個整數 $n$ ($1 \le n \le 10^5$),代表人數。

接下來的 $n$ 行,每行包含兩個整數 $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.