#P8632. [蓝桥杯 2015 国 B] 居民集会
[蓝桥杯 2015 国 B] 居民集会
Problem Description
All residents of Lanqiao Village live along a road of length . The position of each household is measured by its distance from the start of the road. The distance of household from the start is .
Every year, Lanqiao Village holds a gathering. This year, because the population is too large, the village committee decides to hold gatherings at locations: of them are in the middle of the road, and is at the end of the road.
It is known that each household will attend a gathering in the direction away from the start of the road (i.e., towards increasing distance). The travel cost for a household is the product of the number of people in the household and the travel distance.
Given each household's position and population , find the best gathering locations such that the total travel cost of all people in the village is minimized.
Input Format
The first line contains two integers , representing the number of households in Lanqiao Village and the length of the road.
The next lines each contain two integers , representing the distance of household from the start of the road and the number of people in the household.
Output Format
Output one line containing one integer, representing the total travel cost of all people in the village.
6 10
1 3
2 2
4 5
5 20
6 5
8 7
18
Hint
[Sample Explanation]
If gatherings are held at distances from the start, the distances that the households need to walk are , respectively. The total travel cost is $1 \times 3 + 0 \times 2 + 1 \times 5 + 0 \times 20 + 2 \times 5 + 0 \times 7 = 18$.
[Constraints]
For of the testdata, .
For of the testdata, , , , , .
For of the testdata, , , , , .
Translated by ChatGPT 5