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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string>

using namespace std;

int main()
{
    unsigned int n, m, x=0, pom=999, z=0, w;
    cin >> n;
    unsigned int tab[n], tab_d[n];
    string k;
    for(unsigned int i=0; i<n; i++)
    {
        cin >> w;
        tab[i] = w;
        tab_d[i] = w;
    }
    cin >> m;
    cin >> k;
    int s=0;
    while(0 == 0)
    {
        if(x >= n)
            x = 0;
        if(z >= m)
            z = 0;
        if(k[z] == 'P')
        {
            tab[x] -= 1;
        }
        else if (k[z] == 'W')
        {
            tab[x] += 1;
        }
        if(tab[x] <= 0)
        {
            pom = s + 1;
            break;

        }
        x++;
        z++;
        s++;
        int sra=0;
        if(s==1000)
        {

            for(unsigned int j=0; j<n; j++)
            {
                if(tab[j] > tab_d[j])
                {
                    sra++;
                }
            }
        }
        if(sra == n)
        {
            cout << -1;
            return 0;
        }
    }
    cout << pom;

}