Rest Stops
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 l (1 ≤ l ≤ 10^6
) meters. Farmer John will hike the trail at a constant travel rate of r[F]
(1 ≤ r[F]
≤ 10^6
) seconds per meter. Since he is working on his stamina, he will not take any rest stops along the way.
Bessie, however, is allowed to take rest stops, where she might find some tasty grass. Of course, she cannot stop just anywhere! There are n (1 ≤ n ≤ 10^5
) rest stops along the trail; the i-th stop is x[i]
(0 < x[i]
< l) meters from the start of the trail and has a tastiness value c[i]
(1 ≤ c[i]
≤ 10^6
). If Bessie rests at stop i for t seconds, she receives c[i]
* t tastiness units.
When not at a rest stop, Bessie will be hiking at a fixed travel rate of r[B]
(1 ≤ r[B]
≤ 10^6
) seconds per meter. Since Bessie is young and fit, r[B]
is strictly less than r[F]
.
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.
Input
The first line contains four integers: l, n, r[F]
and r[B]
. The next n lines describe the rest stops. For each i between 1 and n, the (i + 1)-st line contains two integers x[i]
and c[i]
, describing the position of the i-th rest stop and the tastiness of the grass there.
It is guaranteed that r[F]
> r[B]
, and 0 < x[1]
< ... < x[n]
< l. Note that r[F]
and r[B]
are given in seconds per meter!
Output
Print a single integer: the maximum total tastiness units Bessie can obtain.
Example
In this example, it is optimal for Bessie to stop for 7 seconds at the x = 7 rest stop (acquiring 14 tastiness units) and then stop for an additional 1 second at the x = 8 rest stop (acquiring 1 more tastiness unit, for a total of 15 tastiness units).