#P15726. [JAG 2023 Summer Camp #3] Best parentheses
[JAG 2023 Summer Camp #3] Best parentheses
题目描述
A string consisting only of parentheses ‘(’ and ‘)’ is called balanced if it satisfies one of the following conditions.
- It is an empty string.
- It is a concatenation of two non-empty balanced strings.
- It is a concatenation of ‘(’, , and ‘)’, for some balanced string .
You are given characters of parentheses and integers . Then, you have to choose zero or more integers so that they satisfy the following conditions.
- .
- The concatenation of is a balanced string.
Note that the above conditions are always satisfied if you choose zero integers.
Your task is to maximize .
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} &n \\ &s_1 s_2 \cdots s_n \\ &c_1 \ c_2 \ \cdots \ c_n \end{aligned} $$The first line consists of an integer (). The second line consists of characters , each of which is either ‘(‘ or ‘)’. The third line consists of integers ().
输出格式
Output in a line the maximum possible value of by choosing zero or more integers .
5
()(()
3 -9 -2 1 0
3
6
)()()(
-3 1 -4 1 -5 9
0