#P6884. [COCI 2016/2017 #3] Kvalitetni
[COCI 2016/2017 #3] Kvalitetni
Description
An arithmetic expression is defined as “high-quality” if and only if it consists only of parentheses, numbers, the multiplication sign, and the addition sign.
A high-quality arithmetic expression is defined recursively as follows:
- It contains only one positive real number that is less than or equal to . The form of such an expression is:
For example, when , then is a high-quality arithmetic expression.
- If are all high-quality arithmetic expressions, and the sum of these high-quality arithmetic expressions is less than or equal to , then
are also high-quality arithmetic expressions.
You are given an arithmetic expression in which all numbers are replaced by question marks. Under the condition that this expression is a high-quality arithmetic expression, find the maximum possible value of this expression.
Input Format
The first line contains a positive integer .
The second line contains positive integers separated by spaces, representing .
The third line contains a high-quality arithmetic expression where all numbers are replaced by ?. This expression contains only ?, +, *, (, ).
Output Format
This problem uses Special Judge.
You need to output the maximum value of this expression.
Your solution is accepted if and only if the absolute difference between your output and the standard answer is .
2
10 6
((?)+(?))
6.00000
3
2 5 3
(((?)+(?))*(?))
6.00000
3
2 10 6
((?)*(?)*(?))
8.0000000
Hint
Explanation for Sample 1
The expression satisfies the conditions, so it is a high-quality arithmetic expression. It is easy to prove that is the maximum value of this expression.
Explanation for Sample 2
For the expression , the maximum value can be achieved.
Explanation for Sample 3
For the expression , the maximum value can be achieved.
Constraints
For of the testdata, it holds that , , and the expression length is .
Notes
Translated from COCI2016-2017 CONTEST #3 T4 Kvalitetni.
Translated by ChatGPT 5
京公网安备 11011102002149号