No.297 Card Expression
タグ : / 解いたユーザー数 150
作問者 :
Problem Statement
Each of $N$ cards has a single digit or $+,-$ written on it.
You want to arrange all the cards in a horizontal row in any order you like to form an expression.
Here, the expression must not begin or end with an operator, and no two operators may be adjacent.
Leading zeros $(012,003$ and other ways of writing a number with $0$ at the front$)$ are allowed.
Find the maximum and minimum values of the expressions that can be formed.
Input
$N$ $c_1 \ c_2 \ ... \ c_N$
Line $1$ contains $N$.
Line $2$ contains the characters written on the cards, separated by spaces.
$3 \le N \le 15$
$c_i$ is one of '$0$'–'$9$'$,$'$+$'$,$'$-$'.
At least $1$ operator is included.
The number of operators is less than the number of digits.
Output
Output the maximum and minimum values, separated by a space.
Sample
Sample 1
Input
5 1 1 1 + +
Output
3 3
Only $1+1+1$ can be formed.
Sample 2
Input
3 1 3 -
Output
2 -2
Arranging them as $3-1$ gives $2$, and arranging them as $1-3$ gives $-2$.
Sample 3
Input
5 1 2 3 - 4
Output
431 -431
$432-1=431 \ $ and $ \ 1-432=-431$
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。