1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>

using namespace std;

int main() {
    int friendsCount = 0;
    scanf("%d", &friendsCount);
    int friendsMoney[friendsCount];
    int friendMoney = 0;
    for(int i=0; i<friendsCount; i++){
        scanf("%d", &friendMoney);
        friendsMoney[i] = friendMoney;
    }

    int cycleLength = 0;
    scanf("%d\n", &cycleLength);
    int cycles[cycleLength];
    char cycle;
    for(int i=0; i<friendsCount; i++){
        scanf("%c", &cycle);
        if(cycle == 'W'){
            cycles[i] = 1;
        } else {
            cycles[i] = -1;
        }
    }

    int boyNo = 0;
    int cycleNo = 0;
    int count = 0;
    while(true){
        count++;
        friendsMoney[boyNo] = friendsMoney[boyNo] + cycles[cycleNo];
        if(friendsMoney[boyNo] == 0){
            break;
        }
        boyNo = (boyNo+1)%friendsCount;
        cycleNo = (cycleNo+1)%cycleLength;
    }

    printf("%d", count);
    return 0;
}