A9245 | Find Maximum
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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=2^{0}+2^{1}+2^{3})$ , 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$ .
For example, if $n=4$ and $x=11$ $(11=2^{0}+2^{1}+2^{3})$ , 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$ .
输入格式
The first line contains integer $n$ $(1<=n<=10^{5})$ — the number of array elements. The next line contains $n$ space-separated integers $a_{0},a_{1},...,a_{n-1}$ $(0<=a_{i}<=10^{4})$ — 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 .
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 .
输出格式
Print a single integer — the maximum value of function $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=2^{0}=1,f(0)=0,f(1)=a_{0}=3$ .
In the second sample $m=2^{0}+2^{1}+2^{3}=11$ , the maximum value of function equals $f(5)=a_{0}+a_{2}=17+10=27$ .
In the second sample $m=2^{0}+2^{1}+2^{3}=11$ , the maximum value of function equals $f(5)=a_{0}+a_{2}=17+10=27$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted