Games
Time limit2sMemory limit1024 MB
Each game's rules must be learned once before unlimited replays, and the task asks for the maximum total rating reachable within d minutes.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Kile has returned from a board game fair with games. Before playing a game, he must learn its rules. Learning the rules of the -th game takes minutes. Once the rules are learned, the game can be played. Playing the -th game takes minutes. Each game also has its own rating .
In the coming days, Kile plans to spend at most minutes on board games. He wants the maximum sum of ratings of the games he can play. Each game can be played an arbitrary number of times.
Input
The first line contains integers and (), the number of games and the time planned for playing games.
The -th of the following lines contains integers , and (, , ), the time required to learn the rules, the time required to play, and the rating of the -th game.
Output
Print the maximum sum of the ratings of the games played on a single line.