#P2209. [USACO13OPEN] Fuel Economy S
[USACO13OPEN] Fuel Economy S
题目描述
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 John 决定去一次跨国旅游度假。为了不让他的奶牛们感到被抛弃,他决定租一辆大卡车来带他的奶牛们一起旅行。
这辆卡车有一个很大的油箱,可以装下 个单位的油(),不幸的是,卡车的耗油量也很大,卡车每运动一个单位的距离,就要消耗一个单位的油。Farmer John 要在他的旅程中走 个单位的距离。()
因为 FJ 直到他可能要几次在旅途中停下,给油箱加油,所以他把在旅途沿路上的 个加油站的记录做成了表格。对于第 个加油站,他记录了加油站与起点的距离 (),以及加油站中每单位油的价格 ()。
已知以上所给的信息,以及 FJ 在路途开始时拥有的燃油的数量 (),请计算出 FJ 到达目的地时花费的油费用的最小值。如果 FJ 无法到达旅途的终点,那么请输出 -1
。本题的答案可能无法使用 32 位整数储存。
输入格式
第一行: 四个整数:
接下来 行:每一行都有两个整数 与 ,意义如上所述
输出格式
一个整数,如果 FJ 无法到达旅途的终点,那么输出 -1
,否则输出 FJ 到达目的地时花费的油费用的最小值。
4 10 3 17
2 40
9 15
5 7
10 12
174
提示
样例解释:FJ 先移动 个单位,然后停下购买 个单位的油(要花费 )。然后一直前进到距离起点 个单位的地方,此时油箱为空。这时向油箱里加满油(要花费 )。再向前走 个单位,加 个单位的油(花费 )。最后一直走到终点。此时总花费是 。