MapleStory
Time limit2sMemory limit1024 MB
Given N hunting grounds with entry experience thresholds and per-minute rates, plus travel times, find the maximum experience obtainable within T minutes.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Shortest path, Greedy, Graph
- Solved
- No attempts yet
Problem
Sangwon will play MapleStory during winter break. Since he will be busy once the semester starts, he wants to gain as many levels as possible during the break.

MapleStory has many hunting grounds. Each hunting ground has various characteristics such as the minimum level required to enter, the terrain, the monster level, the number of monsters, and burning. Since experience is what matters most to Sangwon, he simplified each hunting ground to its minimum experience required to enter and the experience gained per minute. After he starts hunting, every minute he decides whether to keep hunting at his current ground or move to another ground. Sangwon spent all his money on cosmetic items and cannot teleport, so he walks between hunting grounds. He cannot hunt while moving between grounds, so he gains no experience then.
Since his character starts with experience, he chooses one of the hunting grounds whose minimum experience required to enter is and starts hunting there. Report the maximum experience Sangwon can gain during the break.
Input
The first line gives the number of hunting grounds () and the length of the break in minutes ().
The next lines give the characteristics of the -th hunting ground: the minimum experience required to enter and the experience gained per minute . ()
The next lines give the time required to move between hunting grounds. The -th number in the -th line is , the time in minutes required to move from hunting ground to hunting ground and enter it. (, , )
There is always at least one hunting ground whose minimum experience required to enter is .
Output
Print the maximum experience Sangwon can gain during the break.