cswork / OA打开练习工作台

AmazonOA #75

Move Units (Protect Cities)

估计中等可在线判题

考点(AI 标注)贪心调度动规入门

unit[i]=1 means city i has one unit; each unit can stay where it is or, when i>1, move one step to the left, at most once. A city is covered if it has at least one unit; the population of a city covered more than once counts only once. Find the maximum total covered population.

输入格式

The first line contains n (1..100000), the second line contains n populations (1..10000), and the third line contains a 01 string of length n.

输出格式

Output a single integer answer.

样例 1

输入:

5
10 5 8 9 6
01101

输出:

27

样例 2

输入:

1
7
0

输出:

0

样例 3

输入:

2
3 8
11

输出:

11

样例说明

Example 1: the unit in city 2 moves to 1, the unit in city 3 stays at 3, and the unit in city 5 moves to 4, for a population of 10+8+9=27. Example 2: there are no units, so the coverage is 0. Example 3: both units stay in place, for a population of 3+8=11.