#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using ordered_set= tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define MAX 200005
#define inf 1e9
#define pi acos(-1)
const ll mod=1000000007;
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
double make_radian(double x){return (x*pi)/180;}
double make_degree(double x){return (x*180)/pi;}
ld distance(ld a,ld b,ld x,ld y) {ld ans=sqrtl(((a-x)*(a-x))+((b-y)*(b-y)));return ans;}
bool point_on_segment(ld a,ld b,ld c,ld d,ld x,ld y){if(distance(a,b,c,d)==distance(a,b,x,y)+distance(x,y,c,d)) return true;else return false;}
ld point_checking(ld a,ld b,ld c,ld d,ld x,ld y){ld ans=(a*(d-y))-(b*(c-x))+((c*y)-(d*x));return ans;/*pos==anti-clock,neg==clockwise,zero==on_line*/}
string dtob(ll n){string s;for(ll i=63;i>=0;i--){if(n&(1LL<<i)) s.pb('1');else s.pb('0');}return s;}
ll btod(string x){ll dec(0);reverse(x.begin(),x.end());for(int i=0;i<x.size();i++)if(x[i]=='1')dec+=pow(2LL,i);return dec;}
void _(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
void solve()
{
int n;cin>>n;
vector<int> vc(n),pref(n);
int total=0;
for(int i=0;i<n;i++)
{
cin>>vc[i];
total+=vc[i];
pref[i]=total;
}
string s;cin>>s;
int ans=0,sum=0;
for(int i=n-1;i>=0;i--)
{
if(s[i]=='1')
{
if(i>0) ans=max(ans,sum+pref[i-1]);
sum+=vc[i];
}
}
ans=max(sum,ans);
cout<<ans<<endl;
}
int main()
{
_();
ll t,tt;
t=1;
//cin>>t,tt=t;
while(t--) solve();
}
734B - Anton and Digits | 1080A - Petya and Origami |
1642D - Repetitions Decoding | 1440A - Buy the String |
1658F - Juju and Binary String | 478A - Initial Bet |
981A - Antipalindrome | 365A - Good Number |
1204B - Mislove Has Lost an Array | 1409D - Decrease the Sum of Digits |
1476E - Pattern Matching | 1107A - Digits Sequence Dividing |
1348A - Phoenix and Balance | 1343B - Balanced Array |
1186A - Vus the Cossack and a Contest | 1494A - ABC String |
1606A - AB Balance | 1658C - Shinju and the Lost Permutation |
1547C - Pair Programming | 550A - Two Substrings |
797B - Odd sum | 1093A - Dice Rolling |
1360B - Honest Coach | 1399C - Boats Competition |
1609C - Complex Market Analysis | 1657E - Star MST |
1143B - Nirvana | 1285A - Mezo Playing Zoma |
919B - Perfect Number | 894A - QAQ |