/* Adrian Brodzik */ #include<iostream> #include<vector> using namespace std;int n,*o,m,a,i,e;char*c;bool b=false;int main(){ios_base::sync_with_stdio(0);cin>>n;o=new int[n];for(i=0;i<n;i++){cin>>a;o[i]=a;}cin>>m;c=new char[m];cin>>c;a=0;while(!b){for(i=0;i<n;i++){a++;if(c[e]=='W')o[i]++;else{o[i]--;if(o[i]<=0){b=true;break;}}if(e>=m-1)e=0;else e++;if(a>=1000000000){cout<<-1<<endl;return 0;}}}cout<<a<<endl;return 0;}
1 2 3 4 | /* Adrian Brodzik */ #include<iostream> #include<vector> using namespace std;int n,*o,m,a,i,e;char*c;bool b=false;int main(){ios_base::sync_with_stdio(0);cin>>n;o=new int[n];for(i=0;i<n;i++){cin>>a;o[i]=a;}cin>>m;c=new char[m];cin>>c;a=0;while(!b){for(i=0;i<n;i++){a++;if(c[e]=='W')o[i]++;else{o[i]--;if(o[i]<=0){b=true;break;}}if(e>=m-1)e=0;else e++;if(a>=1000000000){cout<<-1<<endl;return 0;}}}cout<<a<<endl;return 0;} |