AmazonOA #267
Maximize Protected City Population
估计中等可在线判题
Cities are arranged in a row, and unit[i]=1 means a unit is initially there. A unit may stay or move once to the adjacent city on its left; a unit in the first city can only stay. In the end, a city with at least one unit contributes population[i] once; overlapping units do not contribute again. Find the maximum protected population.
输入格式
The first line contains n, the second line population, and the third line a 01 string unit of length n. The original text only kept the constraint that the two arrays have equal length, with no numeric bounds; this site uses 1≤n≤200000, 0≤population[i]≤10^9.
输出格式
Output a single integer, the answer.
样例 1
输入:
5
10 5 8 9 6
01101
输出:
27
样例 2
输入:
2
7 4
01
输出:
7
样例 3
输入:
3
1 100 1
011
输出:
101
样例说明
The answers are 27, 7 and 101. In the third example two units cannot count the 100 in the middle twice.