Gas Station
Time limit1sMemory limit1024 MB
Find the minimum fuel cost to drive from the first gas station to position X, given each station's price, fuel stock, and the tank capacity F.
Problem
Eunha worked hard and finally bought a new car. For a test drive, she plans to drive along a straight road to the destination. The destination is quite far, so she wants to refuel at gas stations along the way. During the test drive, the following conditions must be met.
- The -th gas station is kilometers to the right of the origin of the road. Fuel bought there costs per liter, and the station has a total of liters.
- At a gas station, she can buy any amount of fuel up to liters.
- After refueling at any gas station, the fuel in the car must not exceed the fuel capacity liters.
- The car can travel 1 kilometer on 1 liter of fuel.
- The new car has no fuel before the test drive. The starting point of the car is the first gas station.
- The destination is kilometers to the right of the origin of the road.
Eunha does not want to waste her hard-earned money on fuel, so she wants to reach the destination at minimum cost. You must help Eunha.
Input
The first line contains the number of gas stations , the destination , and the fuel capacity , separated by spaces. (; )
From the second line, lines describe the gas stations. For every , line contains , , and , separated by spaces. (; ; ) No two gas stations are at the same position, and the positions are given in ascending order. That is, for all .
Output
If the destination cannot be reached by any route during the test drive, print -1 on the first line. Otherwise, print the minimum cost to complete the test drive on the first line.