Scoreboard Tampering
Time limit1sMemory limit128 MB
Given the frozen scoreboard and all remaining submission logs, decide whether B can share or reassign them to end strictly ahead of A, and output the lexicographically smallest plan.
- Level
Hard8 of 10
- Topics
- Greedy, Implementation, Brute force, Game theory
- Solved
- No attempts yet
Problem
The contest ranks students like this. A student who solves more problems ranks higher. When two students solve the same number of problems, the one with the lower penalty ranks higher.
The penalty counts solved problems only. If a student needed submissions to get a problem accepted for the first time, that problem adds to the penalty, and the student's penalty is the sum of those values over the solved problems.
Submitting again to an already solved problem does not change the penalty. A problem that is still unsolved when the contest ends adds nothing to the penalty, no matter how many wrong submissions it got. A real contest also counts the time of the accepted submission, but this problem ignores time and looks only at the number of submissions.
Four hours into the contest the scoreboard stopped updating. Student B wants to win this contest, but was not sure about beating student A, the favorite. After thinking it over, B decided to use the frozen scoreboard, tamper with the records and take the prize money.
For every submission log that is still to come, B applies one of the following four operations.
- Make it look as if A made the same submission. The owner of the log and A then get the same result for that submission. This operation cannot be used on a log of A.
- Make it look as if B made the same submission. The owner of the log and B then get the same result for that submission. This operation cannot be used on a log of B.
- Make it look as if both A and B made the same submission. The owner of the log, A and B all get the same result for that submission. This operation cannot be used on a log of A or on a log of B.
- Do nothing. The log applies only to its owner, as usual.
B has analyzed every submission log that will arrive before the contest ends. B also found out that no student other than A or B has a chance of winning.
You dislike cheating, but you find the question itself interesting. Decide whether B can tamper with the remaining logs, beat A and win the contest.
Input
The first line contains the number of contest problems and the number of remaining submission logs . (, )
The second line contains , the number of problems A has solved so far, and , the number of problems B has solved so far. ()
The third line contains the problem numbers A has solved, in increasing order. The fourth line contains the problem numbers B has solved, in increasing order. The line of a student who has solved nothing is an empty line. Problem numbers are integers between and , and no number is given twice on the same line.
The fifth line contains A's current penalty and B's current penalty . () A student who has solved nothing always has penalty .
Each of the next lines contains one remaining submission log, in the order the submissions are made. A log is three integers . is , or : for a log of A, for a log of B, for a log of another student. is the problem number, between and . is for a wrong submission and for an accepted one.
Apart from the problems they have already solved, A and B have not submitted to any problem.
Submitting again to an already solved problem changes neither the solved count nor the penalty of that student. Such submissions can arrive any number of times. The student who makes them is not affected, but tampering can still let them affect someone else.
Output
Print YES on the first line if B can win by tampering with the logs, and NO if that is impossible. If A and B end with the same number of solved problems and the same penalty, B is considered to have lost.
If you printed YES, print more lines holding the operation applied to each log, in order, each one of , , or . If several sequences work, print the lexicographically smallest one.