## CCO '18 P1 - Geese vs. Hawks

View as PDF

Points: 10 (partial)
Time limit: 0.6s
Memory limit: 512M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Troy and JP are big hockey fans. Every hockey team played games this season. Each game was between two teams and the team that scored more points won. No game ended in a tie.

Troy's favourite team is the Waterloo Geese and he recorded the outcome of all their games as a string . W if the Geese won their -th game; otherwise L if the Geese lost their -th game. He also recorded that they scored points in their -th game.

JP's favourite team is the Laurier Hawks and he recorded the outcome of all their games as a string . W if the Hawks won their -th game; otherwise L if the Hawks lost their -th game. He also recorded that they scored points on their -th game.

Troy and JP recorded wins/losses and points in the order that their favourite teams played.

A rivalry game is one where the Geese and Hawks played each other. Since neither Troy or JP recorded the opponents their favourite teams faced, they are not sure which games, if any, were rivalry games. They wonder what is the maximum possible sum of points scored by both their teams in rivalry games that matches the information they recorded.

#### Input Specification

The first line contains one integer .

The second line contains string of length consisting of characters W and L.

The third line contains integers .

The fourth line contains string of length consisting of characters W and L.

The fifth line contains integers .

For 10 of the 25 available marks, .

#### Output Specification

Print one line with one integer, the maximum possible sum of points scored in potential rivalry games.

#### Sample Input 1

1
W
2
W
3

#### Output for Sample Input 1

0

#### Explanation for Sample Input 1

Since both the Geese and Hawks won all their games, there could not have been any rivalry games.

#### Sample Input 2

4
WLLW
1 2 3 4
LWWL
6 5 3 2

#### Output for Sample Input 2

14

#### Explanation of Output for Sample Input 2

The fourth game each team played could have been a rivalry game where Geese won with points to the Hawk's points. The third game the Geese played and the second game the Hawks played could have been a rivalry game where the Hawks won with points compared to points of the Geese. The points scored by both teams is and this is the maximum possible.

Note that the first game played by the Geese was a win where they scored 1 goal: this game cannot be against the Hawks, since there is no game where the Hawks scored 0 goals. Similarly, the first game played by the Hawks cannot be used, since the Hawks lost and scored 6 goals, and the Geese never had a game where they scored at least 7 goals.

• commented on March 29, 2020, 8:28 a.m.

I have the same question Geese: W 4 Hawks: L 2 = 2 + 4 = 6 Geese: L 2 Hawks: W 3 = 2 + 3 = 5 Geese: L 3 Hawks: W 5 = 3 + 5 = 8 Geese: W 1 Hawks: L 6 = not possible

Total should be 19?

• commented on March 29, 2020, 8:26 a.m. edit 2

delete this comment pls

• commented on Feb. 27, 2020, 3:37 p.m.

for sample 2, shouldn't the game where the geese lost with 2 points and the hawks won with 3 points count as well? So the total points should be 4 + 2 + 5 +3 + 2 + 3 = 19?

• commented on Feb. 27, 2020, 3:46 p.m.

One of the games was used in another calculation, you are repeating a game. So no.

• commented on May 12, 2019, 8:18 p.m.

Is $O(n^2)$ DP good enough?

• commented on May 12, 2019, 10:06 p.m.

Yes

• commented on May 22, 2018, 9:55 a.m.

they wonder what is the maximum possible sum of points scored by both their teams in rovalry games that matches the information they recorded.

rovalry should be rivalry/capitalized They at start of sentence

go geese