Repaint the ball
Sema and Yura have n balls, each either black or white. Each ball has a value c[i]
and can be repainted a maximum of a[i]
times.
They decide to play a game where, in each turn, a player can repaint a ball to either black or white, or choose to skip their turn. A ball cannot be repainted more than a[i]
times, and it can be repainted in the same color it already is. Sem goes first. The game concludes when no ball can be repainted further or both players skip their turns consecutively.
After the game, Sem collects all the white balls, and Yura takes all the black ones. Each player's score is the sum of the values of their respective balls. Both players aim to maximize their scores. Determine the final scores for both players if they play optimally.
Input
The first line contains a single integer n (1 ≤ n ≤ 10^5
) - the number of balls.
The second line contains n integers c[1]
, c[2]
, ..., c[n]
(1 ≤ c[i]
≤ 10^9
) - the value of the i-th ball.
The third line contains n integers a[1]
, a[2]
, ..., a[n]
(1 ≤ a[i]
≤ 10^9
) - the maximum number of times the i-th ball can be repainted.
The fourth line contains n characters, each either W or B. The i-th character is W if the i-th ball is initially white, and B if it is black.
Output
Output two integers - the scores of Sem and Yura, respectively.