#include <bits/stdc++.h>
int koledzy[1000100];
char napis[1000100];
int main()
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d", &koledzy[i]);
int m;
scanf("%d", &m);
scanf("%s", napis);
int W = 0, P = 0;
for(int i = 0; i < m; ++i)
if(napis[i] == 'W') ++W;
else
++P;
if(W < P)
{
int ruch = 0;
for(;;)
{
if(napis[ruch % m] == 'W')
++koledzy[ruch % n];
else
--koledzy[ruch % n];
if(koledzy[ruch % n] <= 0)
break;
++ruch;
}
printf("%d", ruch+1);
}
else
{
printf("-1");
}
}
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 | #include <bits/stdc++.h> int koledzy[1000100]; char napis[1000100]; int main() { int n; scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%d", &koledzy[i]); int m; scanf("%d", &m); scanf("%s", napis); int W = 0, P = 0; for(int i = 0; i < m; ++i) if(napis[i] == 'W') ++W; else ++P; if(W < P) { int ruch = 0; for(;;) { if(napis[ruch % m] == 'W') ++koledzy[ruch % n]; else --koledzy[ruch % n]; if(koledzy[ruch % n] <= 0) break; ++ruch; } printf("%d", ruch+1); } else { printf("-1"); } } |
English