Bracket Problem Yet Again
시간 제한8초메모리 제한2048 MB
각 k=0부터 n까지에 대해, 최대 k개 위치의 비용을 0으로 만들 수 있을 때 균형 잡힌 괄호 문자열의 최소 비용을 구한다.
문제
A balanced bracket string is a string consisting of '(' and ')', which can make a valid mathematical expression by inserting or in the string or more times.
Bob had learned how to find the balanced bracket string with minimum cost, when the cost is defined as follows.
- If position contains
'(', the cost of the position is ; - If position contains
')', the cost of the position is ; - The cost of a balanced bracket string is the sum of costs of all positions.
While rethinking about the solution, Bob became curious about the following problem.
- Assuming I can make and both for at most different indices, what is the new minimum cost?
As he was unable to solve the modified problem, he asked you to solve it. As Bob is a very selfish person, he wants you to solve it for each possible value of . The indices chosen for need not be a strict subset of the indices chosen for . In other words, the problem must be solved independently for all values of .
입력
The first line contains an even integer , the length of the bracket sequence. ()
The second line contains integers , the costs of using '(' on each index. ()
The third line contains integers , the costs of using ')' on each index. ()
출력
Output integers separated by spaces. is defined by the minimum cost of the problem when .