Rest Stops
InterviewTime limit2sMemory limit512 MB
Bessie rests at grass stops along a trail and must never fall behind Farmer John; maximize total tastiness of eaten grass.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Prefix sum, Math
- Solved
- No attempts yet
Problem
Farmer John and his personal trainer Bessie are hiking up Mount Vancowver. For this problem the mountain is one straight trail of length meters (). Farmer John hikes at a constant rate of seconds per meter (). He is working on his stamina, so he takes no rest along the way.
Bessie is allowed to rest, and at a rest stop she can eat tasty grass. Of course she cannot stop just anywhere. There are rest stops along the trail (). The -th stop is meters from the start of the trail (), and the grass there has tastiness (). If Bessie rests at stop for seconds, she gains tastiness units.
While she is not resting, Bessie travels at a constant rate of seconds per meter (). Bessie is young and fit, so is strictly less than .
The two of them leave the start of the trail at the same moment. Bessie wants to eat as much tasty grass as she can, but she worries about Farmer John. She thinks that if she is behind him on the trail at any moment of the hike, he might lose all motivation to continue.
Find the maximum total tastiness Bessie can obtain while making sure that Farmer John completes the hike.
Input
The first line contains four integers , , , and . The next lines describe the rest stops. For each between and , the -st line contains two integers and , the position of the -th rest stop and the tastiness of the grass there.
It is guaranteed that and that . Note that and are given in seconds per meter.
Output
Print a single integer, the maximum total tastiness Bessie can obtain.
Hint
In the first example it is best for Bessie to rest seconds at the stop at , which gives tastiness units, and then rest more second at the stop at , which gives more unit. The total is .