Role-Playing Game
InterviewTime limit2sMemory limit1024 MB
Pick tasks whose prerequisites are all done, keep total time within m minutes, maximize total experience, and print one valid completion order.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
When Zhenya has free time, he likes to spend it on his favorite role-playing game. Of course, he has a dream: to reach level 255, which means collecting the experience points that level requires. Unfortunately, he does not have much free time, so he wants to use it as efficiently as possible. Help him.
Experience points come from completing tasks. Each task has the time it takes to complete, the number of experience points it gives, and a list of tasks that must be completed before it becomes available.
Find the maximum amount of experience Zhenya can gain in his free time.
Input
The first line contains two integers and (, ), the number of tasks and the number of free minutes Zhenya has. The next lines describe the tasks, one per line. Each line starts with three integers , , and (, ): the number of minutes task takes, the experience points it gives, and the number of tasks that must be completed before task . Then follow distinct integers from to , the numbers of those tasks.
Output
The first line contains a single integer, the maximum experience Zhenya can gain in his free time. The second line contains the numbers of the tasks he must complete to gain that much experience, in the order he must complete them.