49. NTHU Coding Throne 2016 - I. NEXT

0 Judge

Code: 0


NEXT

題目敘述

You probably have heard of the movie "Next" starring Nicolas Cage. In the movie, a man named Cris Johnson can see into his future, but only two minutes ahead. Kerker, a great player top in the World Rankings of Rock-Paper-Scissors games, has the ability as well.

This time, Kerker is playing Rock-Paper-Scissors game with Chuck. They have agreed to the following rules:

  • The game consists of many rounds.

  • In each round, both players secretly choose one of Rock, Paper or Scissors, and then they compare their choices. Rock beats Scissors, Scissors beats Paper and Paper beats Rock.

  • The game is decided by total points earned and lost in each round.

Chuck is a bully, he forced and restricted Kerker that he can only choose Rock, Paper or Scissors a specific number of times in all rounds. This makes Kerker unhappy and he wants to beat Chuck as bad as he could. He decided to use the ability to see what Chuck will choose in the following rounds. Help Kerker to compute the maximum points he could earn.

輸入說明

The first line of the input contains an integer $T$ ($1 \leq T \leq 200$), the number of test cases. Each test case is formatted as follows.

$N\;R\;P\;S$

$c_{1}\;c_{2}\;\cdots\;c_{N}$

$W_{1}\;D_{1}\;L_{1}$

$W_{2}\;D_{2}\;L_{2}$

$\vdots$

$W_{N}\;D_{N}\;L_{N}$

The first line of each test case consists of 4 integers $N$ ($1 \leq N \leq 150$), $R$, $P$ and $S$ ($0 \leq R, P, S \leq 50$) representing that the game consists of $N$ rounds with Kerker can only choose Rock for $R$ times, Paper for $P$ times, and Scissors for $S$ times. It is guaranteed that $R+P+S=N$.

The second line is a string consisting $N$ characters, all of them are an alphabet either R (Rock), P (Paper) or S (Scissors), the $i^{th}$ character denotes that what Kerker see Chuck will choose beforehand with his ability.

The following $N$ lines, each consists of 3 integers $W_i$, $D_i$ and $L_i$ ($-1000 \leq L_i \leq 0 \leq D_i \leq W_i \leq 1000$) representing the points to score for winning, drawing and losing, respectively, in the round $i$.

輸出說明

For each test case, output an integer, which denotes the maximum possible points that Kerker could score, in a line.

範例輸入

2
5 2 2 1
RRRRR
1 0 -1
1 0 -1
1 0 -1
1 0 -1
1 0 -1
1 1 0 0
S
1 0 -5

範例輸出

1
1

提示

no


Judge Setting

run-time limit: 1500 ms
memory limit: 262144 byte
測資數量: 0