問題一覧 > 通常問題

No.297 Card Expression

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 150
作問者 : kzyKT
お気に入りにしたユーザー ProblemId : 464 / 自分の提出
問題文最終更新日: 2026-06-30 17:25:33
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 125 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。