Logo HelloWorld信息学奥赛题库

少儿编程

时间限制:1 s 空间限制:512 MB

#1261. [USACO13OPEN]燃油经济性Fuel Economy

统计

题目描述

Farmer John has decided to take a cross-country vacation. Not wanting his cows to feel left out, however, he has decided to rent a large truck and to bring the cows with him as well!
The truck has a large tank that can hold up to G units of fuel (1 <= G <= 1,000,000). Unfortunately, it gets very poor mileage: it consumes one unit of fuel for every unit of distance traveled, and FJ has a total of D units of distance to travel along his route (1 <= D <= 1,000,000,000).
Since FJ knows he will probably need to stop to refill his tank several times along his trip, he makes a list of all the N fuel stations along his route (1 <= N <= 50,000). For each station i, he records its distance X_i from the start of the route (0 <= X_i <= D), as well as the price Y_i per unit of fuel it sells (1 <= Y_i <= 1,000,000).
Given this information, and the fact that FJ starts his journey with exactly B units of fuel (0 <= B <= D), please determine the minimum amount of money FJ will need to pay for fuel in order to reach his destination. If it is impossible for him to reach the destination, please output -1. Note that the answer to this problem may not fit into a standard 32-bit integer.
Farmer Jhon 决定去一次跨国旅游度假。为了不让他的奶牛们感到被抛弃,他决定租一辆大卡车来带他的奶牛们一起旅行。
这辆卡车有一个很大的油箱,可以装下G个单位的油(1 <= G <= 1,000,000), 不幸的是,卡车的耗油量也很大,卡车每运动一个单位的距离,就要消耗一个单位的油。Farmer Jhon 要在他的旅程中走D个单位的距离。(1 <= D <= 1,000,000,000)
因为FJ直到他可能要几次在旅途中停下,给油箱加油,所以他把在旅途沿路上的N个加油站的记录做成了表格。对于第i个加油站,他记录了加油站与起点的距离X_i(0 <= X_i <= D),以及加油站中每单位油的价格Y_i(1 <= Y_i <= 1,000,000)。
已知以上所给的信息,以及FJ在路途中实际使用的油的数量B(0 <= B <= D),请计算出FJ到达目的地时花费的油费用的最小值。如果FJ无法到达旅途的终点,那么轻输出-1。本题的答案可能无法使用32位整数储存。

输入格式:

第1行: 四个整数: N,G,B,D
第2~1+N行: 每一行都有两个整数X_i与Y_i,意义如上所述

输出格式:

一个整数,如果FJ无法到达旅途的终点,那么输出-1,否则输出FJ到达目的地时花费的油费用的最小值。

输入样例#1:

4 10 3 17
2 40
9 15
5 7
10 12

输出样例#1:

174