#P6713. Maximum Total Points in Same City Derbies

    ID: 19921 Type: Default 1000ms 256MiB

Maximum Total Points in Same City Derbies

Maximum Total Points in Same City Derbies

Troy and JP are hockey fans. In this season, each hockey team plays \(N\) games. Each game is played between two teams, and the team with a higher score wins (ties never occur).

Troy's favorite team, the Waterloo Wild Geese, played \(N\) games. He recorded the outcome in a string \(S\) where \(S_i = \texttt{W}\) if the Wild Geese won the \(i\)-th game and \(S_i = \texttt{L}\) if they lost. Along with this, he recorded the points they scored in each game as an array \(A\), where \(A_i\) denotes the points in the \(i\)-th game.

Similarly, JP's favorite team, the Laurier Golden Hawks, played \(N\) games. He recorded their outcomes in a string \(T\) where \(T_j = \texttt{W}\) if the Golden Hawks won the \(j\)-th game and \(T_j = \texttt{L}\) if they lost. He also recorded the points they scored as an array \(B\), where \(B_j\) denotes the points in the \(j\)-th game.

A same city derby is a game between the Waterloo Wild Geese and the Laurier Golden Hawks. However, since both Troy and JP did not record information about the opposing teams, they cannot directly determine which games were derbies.

Your task is to deduce, from their records, the maximum possible sum of the points scored by both teams in all same city derbies. In a potential derby, one team must have won and the other lost. Hence, if you pair a game \(i\) from Waterloo with a game \(j\) from the Hawks, the pairing is valid if and only if either (a) \(S_i=\texttt{W}\) and \(T_j=\texttt{L}\), or (b) \(S_i=\texttt{L}\) and \(T_j=\texttt{W}\). Each game record can be used at most once.

The score contributed by a derby pairing is \(A_i+B_j\). Determine the maximum possible total score obtained by pairing the games into valid derbies.

inputFormat

The input consists of five lines:

  1. The first line contains an integer \(N\) (the number of games each team played).
  2. The second line contains a string \(S\) of length \(N\), representing the game outcomes for the Waterloo Wild Geese. Each character is either 'W' or 'L'.
  3. The third line contains \(N\) space-separated integers, representing the array \(A\) (the scores of the Wild Geese in each game).
  4. The fourth line contains a string \(T\) of length \(N\), representing the game outcomes for the Laurier Golden Hawks. Each character is either 'W' or 'L'.
  5. The fifth line contains \(N\) space-separated integers, representing the array \(B\) (the scores of the Golden Hawks in each game).

outputFormat

Output a single integer: the maximum total score that can be achieved by selecting valid same city derbies. A valid pairing involves a game from Waterloo and a game from the Hawks where one team won and the other lost, summing their scores.

sample

3
WLL
3 2 4
LWL
1 5 6
18

</p>