P2645 Snooker
Background
Zhenhai High School offers many school-based elective courses, including sports, music, fine arts, radio direction finding, and aviation, nautical, and aerospace model making, striving to ensure that every student can master a presentable hobby by the time they graduate from high school, laying the foundation for lifelong development. Among the sports electives, there is a course on snooker.
In a snooker match there are $21$ balls, including $15$ red balls and $6$ colored balls (yellow, green, brown, blue, pink, black). Two players take turns. The scores for red, yellow, green, brown, blue, pink, and black balls are $1$, $2$, $3$, $4$, $5$, $6$, and $7$ points, respectively. The player with the higher score at the end wins.
The simplified playing rules are as follows:
1. If there are red balls on the table, on odd-numbered turns you must play a red ball; potted red balls are removed from the table.
2. After potting a red ball, you may choose any colored ball to play; the colored ball potted immediately after a red ball is not removed from the table.
3. If there are no red balls left on the table, then the colored balls are played in ascending order of their values; at this time, each potted colored ball is removed from the table.
Penalties for fouls are as follows:
1. If you fail to hit a legal ball, add $4$ points to the opponent’s score.
2. If you hit a ball other than the required legal ball, then if the wrong ball’s value is greater than $4$, add points equal to that ball’s value to the opponent’s score; otherwise, add $4$ points.
A wrongly potted ball is not removed from the table.
Description
Xiao Ar and Xiao Be cannot remember so many snooker rules, so they invented a simpler set of rules.
In this problem, the playing rules are as follows:
- Ball values are the same as in snooker, i.e., $1\sim 7$.
- Xiao Ar will play $n$ turns, and Xiao Be will play $m$ turns. If a ball is potted, the player’s score increases by the ball’s value; if a turn results in a miss, the opponent gains $4$ points. Potted balls are not removed from the table.
Compute the score of the ongoing match up to now.
Input Format
The input has three lines. The first line contains two integers $n$ and $m$, indicating that Xiao Ar played $n$ shots and Xiao Be played $m$ shots. There is a single space between $n$ and $m$. It is not guaranteed that $n-1 \le m \le n$.
The second line contains $n$ space-separated integers, representing Xiao Ar’s $n$ consecutive shots.
The third line contains $m$ space-separated integers, representing Xiao Be’s $m$ consecutive shots.
In the second and third lines: integers from $1$ to $7$ indicate the value of the ball potted, and $0$ indicates a miss.
Output Format
Output a single line with two integers, representing the scores of Xiao Ar and Xiao Be, respectively.
Explanation/Hint
Sample Explanation:
- Xiao Ar potted, in order, a red, black, red, and pink ball, scoring $15$ points ($1+7+1+6=15$).
- Xiao Be potted, in order, a red, black, and red ball, scoring $9$ points ($1+7+1=9$).
Constraints:
For $100\%$ of the testdata, $0\le n,m\le 100,\ 0\le a_i,b_i\le 7$.
Translated by ChatGPT 5