CF353C.Find Maximum

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Valera has array aa , consisting of nn integers a0,a1,...,an1a_{0},a_{1},...,a_{n-1} , and function f(x)f(x) , taking an integer from 00 to 2n12^{n}-1 as its single argument. Value f(x)f(x) is calculated by formula , where value bit(i)bit(i) equals one if the binary representation of number xx contains a 11 on the ii -th position, and zero otherwise.

For example, if n=4n=4 and x=11x=11 (11=20+21+23)(11=2^{0}+2^{1}+2^{3}) , then f(x)=a0+a1+a3f(x)=a_{0}+a_{1}+a_{3} .

Help Valera find the maximum of function f(x)f(x) among all xx , for which an inequality holds: 0<=x<=m0<=x<=m .

输入格式

The first line contains integer nn (1<=n<=105)(1<=n<=10^{5}) — the number of array elements. The next line contains nn space-separated integers a0,a1,...,an1a_{0},a_{1},...,a_{n-1} (0<=ai<=104)(0<=a_{i}<=10^{4}) — elements of array aa .

The third line contains a sequence of digits zero and one without spaces s0s1... sn1s_{0}s_{1}...\ s_{n-1} — the binary representation of number mm . Number mm equals .

输出格式

Print a single integer — the maximum value of function f(x)f(x) for all .

输入输出样例

  • 输入#1

    2
    3 8
    10
    

    输出#1

    3
    
  • 输入#2

    5
    17 0 10 2 1
    11010
    

    输出#2

    27
    

说明/提示

In the first test case m=20=1,f(0)=0,f(1)=a0=3m=2^{0}=1,f(0)=0,f(1)=a_{0}=3 .

In the second sample m=20+21+23=11m=2^{0}+2^{1}+2^{3}=11 , the maximum value of function equals f(5)=a0+a2=17+10=27f(5)=a_{0}+a_{2}=17+10=27 .

首页