문제
Farmer John and his personal trainer Bessie are hiking up Mount Vancowver. For their purposes (and yours), the mountain can be represented as a long straight trail of length
Bessie, however, is allowed to take rest stops, where she might find some tasty grass. Of course, she cannot stop just anywhere! There are
When not at a rest stop, Bessie will be hiking at a fixed travel rate of
Bessie would like to maximize her consumption of tasty grass. But she is worried about Farmer John; she thinks that if at any point along the hike she is behind Farmer John on the trail, he might lose all motivation to continue!
Help Bessie find the maximum total tastiness units she can obtain while making sure that Farmer John completes the hike.
Problem credits: Dhruv Rohatgi
입력
The first line of input contains four integers:
It is guaranteed that
출력
A single integer: the maximum total tastiness units Bessie can obtain.
예제
10 2 4 3
7 2
8 1
15
In this example, it is optimal for Bessie to stop for