#P3819. 松江 1843 路
松江 1843 路
Description
Laifang Road is a road of length meters, with coordinates ranging from to . There are houses on the road. The -th house is located at coordinate and has residents.
The Songjiang 1843 Road bus line will build a bus stop on this road. The city government wants to serve as many people as possible, so it hopes to minimize the sum of distances from every resident’s home to the stop.
Where should the bus stop be built?
Input Format
The first line contains , .
The next lines each contain two integers and .
Output Format
Output one integer: the minimal sum of distances from all residents’ homes to the bus stop.
100 3
20 3
50 2
70 1
110
100 2
0 1
100 10
100
10000000000 5
3282894320 391
4394338332 929
6932893249 181
7823822843 440
9322388365 623
5473201404068
Hint
Sample Explanation 1
When the stop is built at coordinate , the sum of distances is $|20-40| \times 3+|50-40| \times 2+|70-40| \times 1=110$.
Constraints
- For of the testdata, , .
- For of the testdata, , , .
- For of the testdata, , , .
- For all testdata, , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号