luogu#P2645. 斯诺克

斯诺克

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 2121 balls, including 1515 red balls and 66 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 11, 22, 33, 44, 55, 66, and 77 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 44 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 44, add points equal to that ball’s value to the opponent’s score; otherwise, add 44 points.

A wrongly potted ball is not removed from the table.

Problem 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., 171\sim 7.
  • Xiao Ar will play nn turns, and Xiao Be will play mm 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 44 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 nn and mm, indicating that Xiao Ar played nn shots and Xiao Be played mm shots. There is a single space between nn and mm. It is not guaranteed that n1mnn-1 \le m \le n.

The second line contains nn space-separated integers, representing Xiao Ar’s nn consecutive shots.

The third line contains mm space-separated integers, representing Xiao Be’s mm consecutive shots.

In the second and third lines: integers from 11 to 77 indicate the value of the ball potted, and 00 indicates a miss.

Output Format

Output a single line with two integers, representing the scores of Xiao Ar and Xiao Be, respectively.

4 3
1 7 1 6
1 7 1
15 9

Hint

Sample Explanation:

  • Xiao Ar potted, in order, a red, black, red, and pink ball, scoring 1515 points (1+7+1+6=151+7+1+6=15).
  • Xiao Be potted, in order, a red, black, and red ball, scoring 99 points (1+7+1=91+7+1=9).

Constraints: For 100%100\% of the testdata, 0n,m100, 0ai,bi70\le n,m\le 100,\ 0\le a_i,b_i\le 7.

Translated by ChatGPT 5