#P5581. [PA 2015] Hazard
[PA 2015] Hazard
Description
There are people taking turns playing a slot machine game. Initially, person has dollars.
The slot machine can be modeled as a sequence of length containing only and . If you draw , you win dollar; if you draw , you lose dollar.
In round , person draws the -st element of the sequence. In round , person draws the -nd element. In round , person draws the -rd element, and so on. That is, after person finishes drawing, it is person 's turn to draw. In particular, after person finishes drawing, it becomes person 's turn.
After the -th element of the sequence is drawn, the next element drawn will be the -th element. In particular, after the -th element is drawn, the next element drawn will be the -st element.
If in some round a person loses all of their money, the gambling game ends. Find in which round the game ends, or determine that the game will continue forever.
Input Format
The first line contains a positive integer , the number of players.
The second line contains positive integers , where is the initial amount of money held by player .
The third line contains a positive integer , the length of the sequence.
The fourth line contains a string of length consisting only of W and P, representing the sequence, where W means and P means .
Output Format
If the game will continue forever, output -1. Otherwise, output the round in which the game ends.
4
2 3 2 1
3
WPP
12
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号