308066: CF1461F. Mathematical Expression

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Mathematical Expression

题意翻译

给一个长度为$n(n\le 10^5)$的序列$a$,$0 \le a_i\le 9$,现在给定你可以用+,-,*,中的一些符号填到序列中$n-1$个位置上,使得最后的式子运算结果最大,乘法运算优先于加法与减法,请输出最后的式子

题目描述

Barbara was late for her math class so as a punishment the teacher made her solve the task on a sheet of paper. Barbara looked at the sheet of paper and only saw $ n $ numbers $ a_1, a_2, \ldots, a_n $ without any mathematical symbols. The teacher explained to Barbara that she has to place the available symbols between the numbers in a way that would make the resulting expression's value as large as possible. To find out which symbols were available the teacher has given Barbara a string $ s $ which contained that information. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1461F/02106beeaef426549ac520f7998d1f0ec360fdcb.png)It's easy to notice that Barbara has to place $ n - 1 $ symbols between numbers in total. The expression must start with a number and all symbols must be allowed (i.e. included in $ s $ ). Note that multiplication takes precedence over addition or subtraction, addition and subtraction have the same priority and performed from left to right. Help Barbara and create the required expression!

输入输出格式

输入格式


The first line of the input contains a single integer $ n $ ( $ 1 \le n \le 10^5 $ ) — the amount of numbers on the paper. The second line of the input contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \le a_i \le 9 $ ), where $ a_i $ is the $ i $ -th element of $ a $ . The third line of the input contains the string $ s $ ( $ 1 \le |s| \le 3 $ ) — symbols allowed in the expression. It is guaranteed that the string may only consist of symbols "-", "+" and "\*". It is also guaranteed that all symbols in the string are distinct.

输出格式


Print $ n $ numbers separated by $ n - 1 $ symbols — a mathematical expression with the greatest result. If there are multiple equally valid results — output any one of them.

输入输出样例

输入样例 #1

3
2 2 0
+-*

输出样例 #1

2*2-0

输入样例 #2

4
2 1 1 2
+*

输出样例 #2

2+1+1+2

说明

The following answers also fit the first example: "2+2+0", "2+2-0", "2\*2+0".

Input

题意翻译

给一个长度为$n(n\le 10^5)$的序列$a$,$0 \le a_i\le 9$,现在给定你可以用+,-,*,中的一些符号填到序列中$n-1$个位置上,使得最后的式子运算结果最大,乘法运算优先于加法与减法,请输出最后的式子

加入题单

算法标签: