#P6713. [CCO 2018] Geese vs. Hawks

[CCO 2018] Geese vs. Hawks

Description

Troy and JP are hockey fans. In this season, each hockey team plays NN games. Each game is played between two teams, and the team with the higher score wins. There are no ties.

Troy’s favorite team is the Waterloo Geese, and he recorded the result of each game for this team. The results are written as a string SS. If the Geese won the ii-th game, then Si=WS_i=\texttt{W}; otherwise, Si=LS_i=\texttt{L}. He also recorded that in the ii-th game, they scored AiA_i points.

JP’s favorite team is the Laurier Golden Hawks, and he also recorded the result of each game for this team. The results are written as a string TT. If the Golden Hawks won the jj-th game, then Tj=WT_j=\texttt{W}; otherwise, Tj=LT_j=\texttt{L}. He also recorded that in the jj-th game, they scored BjB_j points.

Troy and JP recorded, in order, the results and scores of every game played by their favorite teams.

A crosstown derby means a game between the Waterloo Geese and the Laurier Golden Hawks (because both teams’ home arenas are in Waterloo). Since Troy and JP did not record the opponents in their favorite teams’ games, they cannot determine whether any crosstown derbies happened, nor which games were crosstown derbies. They want to know, based on the information they recorded, what the maximum possible total sum of points scored by both teams across all crosstown derbies is.

Input Format

The first line contains an integer NN.

The second line contains a string SS of length NN, and it is guaranteed that SS contains only W\texttt{W} and L\texttt{L}.

The third line contains NN integers A1,,ANA_1,\ldots ,A_N.

The fourth line contains a string TT of length NN, and it is guaranteed that TT contains only W\texttt{W} and L\texttt{L}.

The fifth line contains NN integers B1,,BNB_1,\ldots ,B_N.

Output Format

Output one line containing one integer, meaning the maximum possible total sum of points scored by both teams across all crosstown derbies.

1
W
2
W
3
0
4
WLLW
1 2 3 4
LWWL
6 5 3 2
14

Hint

Sample Explanation

Sample 1 Explanation

Because both teams won their games, there cannot be any crosstown derbies.

Sample 2 Explanation

The 4th game played by each team could be a crosstown derby: the Geese scored 44 points and the Golden Hawks scored 22 points. The Geese’s 3rd game and the Golden Hawks’ 2nd game could also be a crosstown derby: the Golden Hawks scored 55 points and the Geese scored 33 points. The total sum of points is 4+2+5+3=144 + 2 + 5 + 3 = 14, and this is the maximum possible total.

Note that the Geese won their 1st game and scored 11 point, so that game cannot be against the Golden Hawks, because the Golden Hawks have no game where they scored 00 points. Also, the Golden Hawks’ 1st game cannot be a crosstown derby either, because the Golden Hawks lost their 1st game and scored 66 points, and the Geese never had a game where they scored at least 77 points.

Constraints

For 100%100\% of the testdata, it is guaranteed that 1N1031\le N\le 10^3, 1Ai,Bi1061\le A_i,B_i\le 10^6, Si,Ti{S_i,T_i\in\{W, L}\}.

  • Subtask 1 (4040 points): N10N\le 10 is guaranteed.
  • Subtask 2 (6060 points): No additional constraints.

Notes

This problem is translated from Canadian Computing Olympiad 2020 Day 1 T1 Geese vs. Hawks.

Translated by ChatGPT 5