Feeding Geese
Time limit5sMemory limit1024 MB
Choose which geese to feed, given each goose's waiting window and speed level, to maximize the total cuteness of the fed geese.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Segment tree, Sorting, Intervals
- Solved
- No attempts yet
Problem
There are adorable geese on the KAIST campus. To celebrate them, KAIST will host the KAIST Geese Show for students. The main part of the show is feeding the geese and enjoying their delightful reactions.
You have been chosen as the representative feeder. Your job is to feed the geese optimally so the show is as cute as possible. The -th goose approaches you at time and waits for food for a duration of . Precisely, the -th goose can eat food during the interval . After time , the goose loses interest and leaves.
The -th goose has speed level and cuteness . If you throw food at any time, the fastest waiting goose (the one with the highest ) takes it. That goose then displays its cuteness, adding to the total cuteness score of the show. After eating, the goose is satisfied and leaves. No two geese have the same speed level. Some geese are noisy, so may be negative.
You may throw as much food as you want, with no limit on frequency or quantity. Find the maximum cuteness score the show can reach.
Input
The first line contains two space-separated integers and .
Each of the next lines contains three space-separated integers , , and .
Output
Print the maximum cuteness score of the show.
Constraints
- if
- All values in the input are integers.