CF353C.Find Maximum
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Valera has array a, consisting of n integers _a_0, a_1, ..., a__n - 1, and function f(x), taking an integer from 0 to 2_n - 1 as its single argument. Value f(x) is calculated by formula
, where value bit(i) equals one if the binary representation of number x contains a 1 on the i-th position, and zero otherwise.
For example, if n = 4 and x = 11 (11 = 20 + 21 + 23), then f(x) = _a_0 + _a_1 + _a_3.
Help Valera find the maximum of function f(x) among all x, for which an inequality holds: 0 ≤ x ≤ m.
瓦列拉有一个由 $ n $ 个整数 $ a_0, a_1, \dots, a_{n-1} $ 构成的数组 $ a $,以及一个函数 $ f(x) $,其自变量 $ x $ 为介于 $ 0 $ 到 $ 2^n - 1 $ 之间的整数。函数值 $ f(x) $ 按如下公式计算:
,
其中 $ \text{bit}(i) $ 的值为 $ 1 $ 当且仅当 $ x $ 的二进制表示中第 $ i $ 位为 $ 1 $,否则为 $ 0 $。
例如,若 $ n = 4 $ 且 $ x = 11 ( 11 = 2^0 + 2^1 + 2^3 $),则 $ f(x) = a_0 + a_1 + a_3 $。
请帮助瓦列拉在所有满足不等式 $ 0 \leq x \leq m $ 的 $ x $ 中,找出函数 $ f(x) $ 的最大值。
输入格式
The first line contains integer n (1 ≤ n ≤ 105) — the number of array elements. The next line contains n space-separated integers _a_0, _a_1, ..., a__n - 1 (0 ≤ a__i ≤ 104) — elements of array a.
The third line contains a sequence of digits zero and one without spaces _s_0_s_1... s__n - 1 — the binary representation of number m. Number m equals
.
第一行包含一个整数 $ n ( 1 \leq n \leq 10^5 $)—— 数组元素的个数。
第二行包含 $ n $ 个用空格分隔的整数 $ a_0, a_1, \dots, a_{n-1} ( 0 \leq a_i \leq 10^4 $)—— 数组 $ a $ 的元素。
第三行包含一个由数字 0 和 1 组成、中间无空格的序列 $ s_0s_1\dots s_{n-1} $ —— 这是数字 $ m $ 的二进制表示。数字 $ m $ 等于
。
输出格式
Print a single integer — the maximum value of function f(x) for all
.
输出一个整数——函数 f(x) 在所有 x∈[0,1] 上的最大值。
输入输出样例
输入#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) = _a_0 = 3.
In the second sample m = 20 + 21 + 23 = 11, the maximum value of function equals f(5) = _a_0 + _a_2 = 17 + 10 = 27.
在第一个测试用例中,m=20=1,f(0)=0,f(1)=a0=3。
在第二个样例中,m=20+21+23=11,函数的最大值为 f(5)=a0+a2=17+10=27。
输入解题思路,AI测评打分。不知道怎么写?