#P8632. [蓝桥杯 2015 国 B] 居民集会

    ID: 7691 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2015斜率优化蓝桥杯国赛

[蓝桥杯 2015 国 B] 居民集会

Problem Description

All residents of Lanqiao Village live along a road of length LL. The position of each household is measured by its distance from the start of the road. The distance of household ii from the start is did_i.

Every year, Lanqiao Village holds a gathering. This year, because the population is too large, the village committee decides to hold gatherings at 44 locations: 33 of them are in the middle of the road, and 11 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 tit_i and the travel distance.

Given each household's position did_i and population tit_i, find the best gathering locations p1,p2,p3,p4 (p1p2p3p4=L)p_1,p_2,p_3,p_4\ (p_1 \le p_2 \le p_3 \le p_4 = L) such that the total travel cost of all people in the village is minimized.

Input Format

The first line contains two integers n,Ln, L, representing the number of households in Lanqiao Village and the length of the road.

The next nn lines each contain two integers di,tid_i, t_i, representing the distance of household ii 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 2,5,8,102, 5, 8, 10 from the start, the distances that the 66 households need to walk are 1,0,1,0,2,01, 0, 1, 0, 2, 0, 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 10%10\% of the testdata, 1n3001 \le n \le 300.

For 30%30\% of the testdata, 1n20001 \le n \le 2000, 1L100001 \le L \le 10000, 0diL0 \le d_i \le L, didi+1d_i \le d_{i+1}, 0ti200 \le t_i \le 20.

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1L1061 \le L \le 10^6, 0diL0 \le d_i \le L, didi+1d_i \le d_{i+1}, 0ti1060 \le t_i \le 10^6.

Translated by ChatGPT 5