Codeforces Round 465 (Div. 2)
E
Fafa and Ancient Mathematics
Codeforces
2300
原题
← DF →
翻译中…

Ancient Egyptians are known to have understood difficult concepts in mathematics. The ancient Egyptian mathematician Ahmes liked to write a kind of arithmetic expressions on papyrus paper which he called as Ahmes arithmetic expression.

翻译中…

An Ahmes arithmetic expression can be defined as:

翻译中…
  • "$*d*$" is an Ahmes arithmetic expression, where $*d*$ is a one-digit positive integer;
  • "$(*E*_{1} *op* *E*_{2})$" is an Ahmes arithmetic expression, where $*E*_{1}$ and $*E*_{2}$ are valid Ahmes arithmetic expressions (without spaces) and $*op*$ is either plus $( + )$ or minus $( - )$.
翻译中…

For example

翻译中…

5

翻译中…

,

翻译中…

(1-1)

翻译中…

and

翻译中…

((1+(2-3))-5)

翻译中…

are valid Ahmes arithmetic expressions.

翻译中…

On his trip to Egypt, Fafa found a piece of papyrus paper having one of these Ahmes arithmetic expressions written on it. Being very ancient, the papyrus piece was very worn out. As a result, all the operators were erased, keeping only the numbers and the brackets. Since Fafa loves mathematics, he decided to challenge himself with the following task:

翻译中…

Given the number of plus and minus operators in the original expression, find out the maximum possible value for the expression on the papyrus paper after putting the plus and minus operators in the place of the original erased operators.

翻译中…

Input

翻译中…

The first line contains a string $*E*$ $(1 ≤ |*E*| ≤ 10^{4})$ — a valid Ahmes arithmetic expression. All operators are erased and replaced with '?'.

翻译中…

The second line contains two space-separated integers $*P*$ and $*M*$ ($0 ≤ *min*(*P*, *M*) ≤ 100$) — the number of plus and minus operators, respectively.

翻译中…

It is guaranteed that $*P* + *M* =$ the number of erased operators.

翻译中…

Output

翻译中…

Print one line containing the answer to the problem.

翻译中…

Note

翻译中…
  • The first sample will be $(1 + 1) = 2$.
  • The second sample will be $(2 + (1 - 2)) = 1$.
  • The third sample will be $((1 - (5 - 7)) + ((6 + 2) + 7)) = 18$.
  • The fourth sample will be $((1 + (5 + 7)) - ((6 - 2) - 7)) = 16$.
翻译中…

样例

Input #1
(1?1)
1 0
Output #1
2
InputCopy OutputCopy
Input #2
(2?(1?2))
1 1
Output #2
1
InputCopy OutputCopy
Input #3
((1?(5?7))?((6?2)?7))
3 2
Output #3
18
InputCopy OutputCopy
Input #4
((1?(5?7))?((6?2)?7))
2 3
Output #4
16
InputCopy OutputCopy
题目信息
题号
935E
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
动态规划
树

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