#include<iostream>
using namespace std;
int main()
{
int x,y,z,d=0,f=0,g=0;
cin>>x;
int suma[x];
int tab[x];
for(z=0;z<x;z++){
cin>>tab[z];
suma[z]=0;
}
cin>>y;
char ta[y];
for(z=0;z<y;z++)cin>>ta[z];
do{
for(z=0;z<y;z++){
f++;
if(ta[z]=='W'){
tab[d]++;
suma[d]++;
}
else{
tab[d]--;
suma[d]--;
}
if(tab[d]==0){
g=1;
break;
}
d++;
if(d==x)d=0;
}
if(d==0&&f>0)for(z=0;z<y;z++)if(suma[z]<0)g=2;
}while(g==0);
if(g==2)cout<<"-1";
else cout<<f;
return 0;
}
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 | #include<iostream> using namespace std; int main() { int x,y,z,d=0,f=0,g=0; cin>>x; int suma[x]; int tab[x]; for(z=0;z<x;z++){ cin>>tab[z]; suma[z]=0; } cin>>y; char ta[y]; for(z=0;z<y;z++)cin>>ta[z]; do{ for(z=0;z<y;z++){ f++; if(ta[z]=='W'){ tab[d]++; suma[d]++; } else{ tab[d]--; suma[d]--; } if(tab[d]==0){ g=1; break; } d++; if(d==x)d=0; } if(d==0&&f>0)for(z=0;z<y;z++)if(suma[z]<0)g=2; }while(g==0); if(g==2)cout<<"-1"; else cout<<f; return 0; } |
English