#P13707. [NWERC 2023] Higher Arithmetic
[NWERC 2023] Higher Arithmetic
题目描述
Captchas are getting more and more elaborate. It started with doing simple calculations like , and now, it has evolved into having to distinguish chihuahuas from double chocolate chip muffins.
:::align{center}
:::
To combat the rise of smarter bots, the Internet Captcha Production Company (ICPC) has outdone itself this time: given a distorted image containing many integers, find the maximum value that can be expressed using each of the given integers exactly once, using addition, multiplication, and arbitrary parentheses.
After unsuccessfully trying to solve such a captcha for an hour straight, Katrijn is terribly frustrated. She decides to write a program that outputs a valid arithmetic expression with maximal value.
输入格式
The input consists of:
- One line with an integer (), the number of integers in the captcha.
- One line with integers (), the integers in the captcha.
输出格式
Output a valid arithmetic expression with maximal value, where each integer from the input list is used exactly once. The usual order of operations applies. The output expression may use at most characters and must not contain any spaces. Such an expression exists for any possible input.
If there are multiple valid solutions, you may output any one of them.
4
1 2 3 4
3*((1+2)*4)
3
13 37 1
(1+13)*37
4
1 1 1 1
((1+1)*(1+1))