Good Bye 2018
F
New Year and the Mallard Expedition
Codeforces
2600
原题
← EG →
翻译中…

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

翻译中…

image 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?

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

Note

翻译中…

In the first sample, Bob first walks $5$ meters in $25$ seconds. Then he flies the remaining $5$ meters in $5$ seconds.

翻译中…

In the second sample, Bob first swims $10$ meters in $30$ seconds. Then he flies over the patch of lava for $10$ seconds.

翻译中…

In the third sample, the water pond is much smaller. Bob first swims over the water pond, taking him $3$ seconds. However, he cannot fly over the lava just yet, as he only has one stamina while he needs two. So he swims back for half a meter, and then half a meter forward, taking him $3$ seconds in total. Now he has $2$ stamina, so he can spend $2$ seconds flying over the lava.

翻译中…

In the fourth sample, he walks for $50$ seconds, flies for $10$ seconds, swims for $15$ seconds, and finally flies for $5$ seconds.

翻译中…

样例

Input #1
1
10
G
Output #1
30
InputCopy OutputCopy
Input #2
2
10 10
WL
Output #2
40
InputCopy OutputCopy
Input #3
2
1 2
WL
Output #3
8
InputCopy OutputCopy
Input #4
3
10 10 10
GLW
Output #4
80
InputCopy OutputCopy
题目信息
题号
1091F
所属比赛
时间限制
1 s
内存限制
256 MB
标签
构造
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。