In a distant kingdom, there lived a certain knight. What did this knight do? Play video games of course!
In his most recent video game, there are
Constraints
For all subtasks:
Subtask 1 [30%]
Subtask 2 [30%]
Subtask 3 [40%]
Input Specification
The first line of input will have two space separated integers,
The next
Output Specification
A single integer, the maximum amount of gold the knight can get after
Sample Input 1
3 6
6 1 3 1
7 1 1 1
3 1 9 2
Sample Output 1
28
Explanation for Sample 1
The knight should go to the second NPC but not do its quest. Then, he should go to the third NPC and do its quest twice. This gives him
Sample Input 2
5 7
8 2 10 2
9 1 7 1
1 2 8 1
5 3 2 1
7 1 4 3
Sample Output 2
51
Explanation for Sample 2
The knight should go to the second NPC and do its quest six times.
Sample Input 3
5 557
819777 142 467177 150
647198 31 265541 155
903546 115 261596 138
757957 84 108764 101
935057 137 532908 164
Sample Output 3
4063535
Comments
can you go to an NPC more than once?
no you can't
this is a valid point (should be in the problem statement) For example, it appears that you cannot visit the same few npcs and not do their quests if their 'visiting quest' is better.
Hi, the result of my submission to this problem seems strange. This is the only submission I did during the contest, and the page says the result was "Compilation Error". But according to the ranking page I got 100 points on this problem. Besides, when I submitted the same code again after the contest, it got WA. Is this a bug of the judge system, or did I just misunderstand something?
This comment is hidden due to too much negative feedback. Show it anyway.