Dr. Anne Anderson Coding Contest 1 P5 - Guessing Grades

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types

William just finished his AP English reading comprehension test and is worried about his score. The test has N questions and William remembers all of his answers, which he records in a string S. Each character in the string represents one of his answers: either A, B, C, or D.

Thankfully, his friend Kevin already took the test and got a perfect score. Eager to know how he did, William asks him for his answers so that he can compare.

However, Kevin has a very foggy memory, and only remembers the answers to some questions on the test. For each question, he writes ? if he forgot the answer or the correct answer otherwise, recording them in a string T. He also remembers the total number of questions on the test that have the answer A, B, C, and D, denoting them N_A, N_B, N_C, and N_D, respectively.

William recieves this information in a message from Kevin, but he's not sure what to do with it. As he's a chronic overthinker and a pessimist, he wants to determine the lowest mark he could possibly recieve. Can you write a program to help him?

Constraints

For all subtasks:

N = N_A + N_B + N_C + N_D = |S| = |T|

1 \leq N \leq 10^6

Subtask 1 [5%]

Kevin remembers the answer to every question.

Subtask 2 [60%]

Kevin remembers the answer to no questions.

Subtask 3 [35%]

No additional constraints.

Input Specification

The first line contains the integer N.

The second line contains the string S.

The third line contains the string T.

The fourth line contains the integers N_A, N_B, N_C, and N_D, separated by spaces.

Output Specification

The output contains one integer, the minimum number of questions that William could have gotten right.

Sample Input 1

9
DBCADDACB
D?C???BC?
1 1 2 5

Sample Output 1

4

Explanation for Sample 1

It can be proven that William will always get a minimum of 4 questions right.

The following is a possible answer key that would fulfill Kevin's data and lead to 4 correct answers:

Scantron:             DBCADDACB
Known Answer Key:     D?C???BC?
Possible Answer Key:  DDCDDABCD
Correct:              YNYNYNNYN

Sample Input 2

12
BBCCCBAABAAA
BBCCABCBBABA
3 6 3 0

Sample Output 2

8

Explanation for Sample 2

This case satisfies the conditions of Subtask 1.

William got questions 1, 2, 3, 4, 6, 9, 10, and 12 right, so he got a total of 8 questions right.


Comments

There are no comments at the moment.