Surf
InterviewTime limit4sMemory limit256 MB
Pick waves with no wait-time overlap so the sum of fun points is as large as possible.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Sorting, Binary search
- Solved
- No attempts yet
Problem
You have taken up surfing in Florida, and you have the full schedule of today's waves. For each wave you know the minute it arrives, the fun points you earn by riding it, and how long you have to wait afterwards before you can ride again. The wait covers the ride itself plus the paddle back out to where the waves break.
If you ride the wave that arrives at minute , the next wave you ride has to arrive at minute or later. Anything that arrives earlier is gone before you are back in position.
Taking the wave with the most fun points is not always best. Consider these four waves:
Riding the waves at minutes 8, 10 and 13 earns 110 fun points. Riding the wave at minute 2 keeps you out of position until minute 11, so the only wave left is the one at minute 13, for a total of 100 fun points. The best total here is 110.
Given the complete list of waves for the day, find the largest total of fun points you can earn.
Input
The first line contains one integer (), the number of waves for the day.
Each of the next lines contains three space separated integers , and (): the minute the -th wave arrives, its fun points, and its wait time.
No two waves arrive at the same minute. The waves are not necessarily listed in chronological order.
Output
Print one integer on a single line, the maximum total of fun points you can earn.