Attack the Moles
Time limit10sMemory limit512 MB
Two hands with speed limit V must hit moles at their exact times and positions, with the left hand always left of the right. Find the maximum total points.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
ICPC requires hard training to get good results. Usagi wants to win at ICPC, so today too, Usagi decides to train.
Today's training is whack-a-mole, played many times to sharpen reflexes and memory. Usagi wants to hit the moles as they appear and earn as many points as possible.
The possible mole locations lie on a straight line, and each location's coordinate is its distance from a reference point. While training, Usagi noticed that the location and time of each mole are always the same. Usagi recorded all of this information and decided to analyze it with a computer.
To hit a mole, Usagi must move a hand to the mole's location and strike at exactly the moment the mole appears. A successful hit earns the points for that mole. A strike takes an instant, but a hand can move only so fast. Usagi may use both the left and right hands. The two hands move independently, but the left hand must always stay at a smaller coordinate than the right hand. Find the maximum number of points Usagi can earn under these conditions.
Input
The first line contains , , , and , separated by spaces. They are the number of moles, the maximum speed at which a hand can move, and the initial coordinates of the left and right hands. Each of the next lines contains , , and : the coordinate where the -th mole appears, the time from the start of the game until it appears, and the points earned for hitting it.
N V XLeft XRight
X1 T1 P1
...
XN TN PN
The constraints are , , , , , and . No two moles share the same pair .
Output
Print the maximum number of points Usagi can earn on one line.