题库练习 New Year and the Mallard Expedition
← 上一题 下一题 →

A12364 | New Year and the Mallard Expedition

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Bob is a duck. He wants to get to Alice's nest, so that those two can duck!

![](/uploads/acgo/image/9800e7913221443d_d556f1e10972.jpeg)Duck is the ultimate animal! (Image courtesy of See Bang)The journey can be represented as a straight line, consisting of $n$ segments. Bob is located to the left of the first segment, while Alice's nest is on the right of the last segment. Each segment has a length in meters, and also terrain type: grass, water or lava.

Bob has three movement types: swimming, walking and flying. He can switch between them or change his direction at any point in time (even when he is located at a non-integer coordinate), and doing so doesn't require any extra time. Bob can swim only on the water, walk only on the grass and fly over any terrain. Flying one meter takes $1$ second, swimming one meter takes $3$ seconds, and finally walking one meter takes $5$ seconds.

Bob has a finite amount of energy, called stamina. Swimming and walking is relaxing for him, so he gains $1$ stamina for every meter he walks or swims. On the other hand, flying is quite tiring, and he spends $1$ stamina for every meter flown. Staying in place does not influence his stamina at all. Of course, his stamina can never become negative. Initially, his stamina is zero.

What is the shortest possible time in which he can reach Alice's nest?

输入格式

The first line contains a single integer $n$ ( $1 \leq n \leq 10^5$ ) — the number of segments of terrain.

The second line contains $n$ integers $l_1, l_2, \dots, l_n$ ( $1 \leq l_i \leq 10^{12}$ ). The $l_i$ represents the length of the $i$ -th terrain segment in meters.

The third line contains a string $s$ consisting of $n$ characters "G", "W", "L", representing Grass, Water and Lava, respectively.

It is guaranteed that the first segment is not Lava.

输出格式

Output a single integer $t$ — the minimum time Bob needs to reach Alice.

输入输出样例

输入 #1
1
10
G
输出 #1
30
输入 #2
2
10 10
WL
输出 #2
40
输入 #3
2
1 2
WL
输出 #3
8
输入 #4
3
10 10 10
GLW
输出 #4
80
C++ 编辑器
输入
输出