#P5263. Optimal Mole Whacking Score
Optimal Mole Whacking Score
Optimal Mole Whacking Score
In a game, a total of \(N\) moles will appear along a straight line. The \(i\)-th mole appears at time \(T_i\) at position \(X_i\), and hitting it yields a score of \(P_i\).
At time \(t=0\) (when the game starts), the left hand is at position \(X_{\text{LEFT}}\) and the right hand is at position \(X_{\text{RIGHT}}\) with \(X_{\text{LEFT}} < X_{\text{RIGHT}}\). Both hands hold hammers. They can move at a maximum speed of \(V\) (i.e. in one unit of time, a hand can cover at most \(V\) distance).
A mole appears and vanishes in an instant. In order to hit the mole, at the exact time it appears, one of JYY's hands must be exactly at the mole's position. If this condition is met, JYY can instantly hit the mole and gain the corresponding score; otherwise, the mole is missed.
Both hands can hit moles simultaneously. However, if at any moment during the game the two hands cross (i.e. the left hand's position is not strictly less than the right hand's position), JYY becomes uncomfortable. Hence, the constraint \(X_{\text{LEFT}} < X_{\text{RIGHT}}\) must be maintained at all times.
Your task is to determine the maximum score JYY can possibly achieve.
Note: All formulas are written in \(\LaTeX\) format.
inputFormat
The input begins with a line containing four integers: \(N\), \(V\), \(X_{\text{LEFT}}\) and \(X_{\text{RIGHT}}\), where \(N\) is the number of moles, \(V\) is the maximum speed of each hand, and \(X_{\text{LEFT}}\) and \(X_{\text{RIGHT}}\) are the initial positions of the left and right hands respectively.
Then \(N\) lines follow. The \(i\)-th of these lines contains three integers: \(T_i\), \(X_i\) and \(P_i\) which denote the time, position, and score of the \(i\)-th mole respectively.
You can assume that the moles may appear in arbitrary order; however, you might find it convenient to sort them by their time \(T_i\) (if needed). Additionally, a hand can move in both directions, and the movement constraint is that in a time interval \(\Delta t\), the hand can move at most \(V \times \Delta t\) distance.
outputFormat
Output a single integer which is the maximum total score that can be achieved.
sample
3 1 0 10
2 2 5
3 9 10
5 5 7
22