#P5052. Pokémon Candy Competition
Pokémon Candy Competition
Pokémon Candy Competition
Branimirko is an avid Pokémon Go player who has organized a competition along Ilica street in Zagreb. There are N houses numbered from 1 to N, and M Pokémon scattered among these houses. The competition starts at house number K.
Each Pokémon is located at a distinct house number Ai, is worth Bi candy, and can be caught only within the next Ti seconds. Branimirko can move to an adjacent house in 1 second. When he reaches a house containing a Pokémon and if the total time elapsed is at most Ti (in seconds), he catches the Pokémon and collects the candy. Once caught, a Pokémon disappears from the map.
Your task is to determine the maximum amount of candy Branimirko can collect by planning a route along the houses.
Note: The time taken to move between houses is the absolute difference of their house numbers. Formally, if Branimirko is at house x and moves to house y, it takes |x-y| seconds. A Pokémon located at house Ai can be caught if and only if the time when Branimirko reaches Ai is \( \leq T_i \).
inputFormat
The first line contains three integers: N, M, and K — the number of houses, the number of Pokémon, and the starting house number, respectively.
Each of the next M lines contains three integers: Ai, Bi, and Ti — the house number where the i-th Pokémon is located, the amount of candy it gives, and the time (in seconds) after which it disappears, respectively.
outputFormat
Output a single integer — the maximum amount of candy Branimirko can collect.
sample
10 3 5
3 10 4
8 5 3
6 7 1
12