#TP0000063. Thu điểm trên dải ô (Right Left Wrong)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thu điểm trên dải ô (Right Left Wrong)
Right Left Wrong
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A strip has cells indexed from to . Cell contains a positive integer and a character , either L or R. Initially the score is . In one operation, choose with L at position and R at position . Add to the score, then replace every character in with a dot. Such positions cannot be selected as endpoints later. Maximize the total score over any number of operations.
Input
- The first line contains .
- The second line contains integers .
- The third line contains a string of length consisting of
LandR.
Output
Print a single integer: the maximum obtainable score.
Subtasks
- Subtask 1 (20 points): ; for every ; for every .
- Subtask 2 (30 points): ; for every ; for every .
- Subtask 3 (50 points): ; for every ; for every .
Examples
Input
6
3 5 1 4 3 2
LRLLLR
Output
18
Explanation
The array is and the character string is LRLLLR. Choosing is valid because the endpoints are L and R. This operation yields . Every position becomes a dot afterward. As the sum of all cells is and a cell cannot be scored twice, no higher score is possible. Therefore the answer is 18.