/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
高橋君は音響エンジニアです。彼はコンサート会場の音響設計を担当しています。
会場には数直線上に N 台のスピーカーが設置されており、観客席にある測定点で聞こえる音の強さを計算する必要があります。測定点の座標は P です。
i 番目のスピーカーは座標 X_i に設置されており、出力の強さは V_i です。スピーカーから発せられた音が測定点に届くときの強さは、出力の強さを測定点までの距離で割った値になります。すなわち、i 番目のスピーカーの音が測定点に届くときの強さは \frac{V_i}{|X_i - P|} です。
ただし、測定点と同じ座標にスピーカーがある場合(X_i = P の場合)、距離が 0 となり値が定義できないため、そのスピーカーは計算から除外します。
高橋君は、測定点で聞こえる音の強さの合計、すなわち X_i \neq P であるすべての i について \frac{V_i}{|X_i - P|} の総和を計算したいと考えています。この値を求めてください。
なお、計算対象となるスピーカーが 1 台も存在しない場合(すべてのスピーカーが測定点と同じ座標にある場合)、合計は 0 とします。
制約
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq P \leq 10^9
- -10^9 \leq X_i \leq 10^9
- 1 \leq V_i \leq 10^6
- \displaystyle \sum_{i=1}^{N} V_i \leq 10^6
- N, P, X_i, V_i はすべて整数
- X_i = P となるスピーカーが存在する場合がある
入力
N P X_1 V_1 X_2 V_2 \vdots X_N V_N
- 1 行目には、スピーカーの台数を表す整数 N と、測定点の座標を表す整数 P が、スペース区切りで与えられる。
- 2 行目から (N + 1) 行目には、各スピーカーの情報が与えられる。
- (1 + i) 行目には、i 番目のスピーカーの座標 X_i と出力の強さ V_i が、スペース区切りで与えられる。
出力
測定点で聞こえる音の強さの合計を 1 行で出力せよ。
なお、真の値との絶対誤差または相対誤差が 10^{-4} 以下であれば正解とみなす。
入力例 1
3 0 -2 4 1 3 0 5
出力例 1
5.00000000000000000000
入力例 2
4 -3 -3 10 -4 2 1 8 -1 6
出力例 2
7.00000000000000000000
入力例 3
10 7 -5 24 0 14 3 8 6 15 7 100 8 9 10 21 15 32 20 39 100 93
出力例 3
45.00000000000000000000
入力例 4
30 -1000000000 -1000000000 50000 -999999999 12000 -999999998 24000 -999999990 35000 -999999900 18000 -999999000 42000 -999990000 16000 -999900000 27000 -999000000 31000 -990000000 22000 -900000000 45000 -750000000 15000 -500000000 38000 -250000000 19000 -1 29000 0 33000 1 17000 100 26000 10000 14000 1000000 41000 100000000 23000 250000000 37000 500000000 11000 750000000 34000 900000000 21000 999000000 28000 999900000 13000 999999998 39000 999999999 20000 1000000000 43000
出力例 4
27723.90413112317764898762
入力例 5
1 1000000000 1000000000 1000000
出力例 5
0.00000000000000000000
Score : 200 pts
Problem Statement
Takahashi is an audio engineer. He is in charge of the acoustic design of a concert venue.
There are N speakers installed on a number line in the venue, and he needs to calculate the sound intensity heard at a measurement point in the audience area. The coordinate of the measurement point is P.
The i-th speaker is installed at coordinate X_i, and its output power is V_i. The sound intensity from a speaker when it reaches the measurement point is given by its output power divided by the distance to the measurement point. That is, the sound intensity reaching the measurement point from the i-th speaker is \frac{V_i}{|X_i - P|}.
However, if a speaker is at the exact same coordinate as the measurement point (i.e., X_i = P), the distance becomes 0 and the value is undefined, so that speaker is excluded from the calculation.
Takahashi wants to calculate the total sound intensity heard at the measurement point, which is the sum of \frac{V_i}{|X_i - P|} over all i such that X_i \neq P. Find this value.
If there are no speakers to include in the calculation (i.e., all speakers are located at the measurement point), the total sum is considered to be 0.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq P \leq 10^9
- -10^9 \leq X_i \leq 10^9
- 1 \leq V_i \leq 10^6
- \displaystyle \sum_{i=1}^{N} V_i \leq 10^6
- N, P, X_i, and V_i are all integers.
- There may be speakers where X_i = P.
Input
N P X_1 V_1 X_2 V_2 \vdots X_N V_N
- The first line contains an integer N, representing the number of speakers, and an integer P, representing the coordinate of the measurement point, separated by a space.
- The 2-nd through (N + 1)-th lines contain information about each speaker.
- The (1 + i)-th line contains the coordinate X_i and the output power V_i of the i-th speaker, separated by a space.
Output
Print the total sound intensity heard at the measurement point in a single line.
Your output will be considered correct if the absolute or relative error from the true value is at most 10^{-4}.
Sample Input 1
3 0 -2 4 1 3 0 5
Sample Output 1
5.00000000000000000000
Sample Input 2
4 -3 -3 10 -4 2 1 8 -1 6
Sample Output 2
7.00000000000000000000
Sample Input 3
10 7 -5 24 0 14 3 8 6 15 7 100 8 9 10 21 15 32 20 39 100 93
Sample Output 3
45.00000000000000000000
Sample Input 4
30 -1000000000 -1000000000 50000 -999999999 12000 -999999998 24000 -999999990 35000 -999999900 18000 -999999000 42000 -999990000 16000 -999900000 27000 -999000000 31000 -990000000 22000 -900000000 45000 -750000000 15000 -500000000 38000 -250000000 19000 -1 29000 0 33000 1 17000 100 26000 10000 14000 1000000 41000 100000000 23000 250000000 37000 500000000 11000 750000000 34000 900000000 21000 999000000 28000 999900000 13000 999999998 39000 999999999 20000 1000000000 43000
Sample Output 4
27723.90413112317764898762
Sample Input 5
1 1000000000 1000000000 1000000
Sample Output 5
0.00000000000000000000