BnPC
문제
You are playing your favorite game, Basements and Pigeonlike Creatures, for the umpteenth time. You know the game pretty well, but you have never spent enough time on it to figure out the best strategy. That is, until now. The game consists of a certain sequence of events, such as battling a monster or saving a cat from a tree, and you need to complete all events to win. Attached to each event is an attribute, such as strength, and a threshold, some positive integer. If your attribute score matches or exceeds the threshold, you successfully complete the event! If not, it is unfortunately game over and your total score will be zero.
If you complete all the events successfully, your score depends on how well you did during these events. If your attribute score matches the threshold of an event exactly, you get 0 points, barely scraping by that event. If you exceed the threshold, you get points equal to your attribute score that was used for that event.
You are now at the final part of the game, but first you have some attribute points to spend to increase your attribute scores. You know what events will happen during the final part of the game, so all that is left is to figure out what attributes to increase.
입력
The input consists of:
- One line containing an integer () and an integer (), the number of attributes and the number of attribute points you can still spend.
- lines, each containing a distinct attribute name, and an integer (), the current score you have in that attribute.
- One line containing an integer (), the number of events.
- lines each describing one event, containing the name of the attribute that is used, and an integer (), the threshold for this event.
Attribute names consist of upper case English letters (A-Z), and have a length between and characters inclusive.
출력
Output the maximum score you can get from the events.
예제
예제 1
2 3 STR 15 CON 12 2 STR 17 CON 14
0
예제 2
3 7 JUMP 5 RUN 7 FLY 0 4 FLY 0 JUMP 6 RUN 10 RUN 8
31