問題一覧 > 通常問題

No.505 Card Expression 2

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 210
作問者 : kzyKT / テスター : ixmel
お気に入りにしたユーザー ProblemId : 1342 / 自分の提出
問題文最終更新日: 2026-06-25 19:00:09
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. Show the original
yukicoder contest 161 (順位表) の他の問題:

Problem Statement

$N$ cards, each with an integer from $-9 \ $ to $ \ 9$ written on it, are lined up in a row.
You want to form an expression by placing $1$ card with one of $+,-,×,÷$ written on it between each pair of adjacent integer cards. $($There are infinitely many cards of each kind.$)$
The operators have no precedence; the expression is evaluated from left to right.
Find the maximum possible value of the resulting expression.

[Handling of $÷$]
・Division by 0 is not allowed, so it must not be placed before a 0.
・If the division is not exact, the fractional part is truncated toward 0 $($ignored$)$.

Input

$N$
$a_1 \ a_2 \ ... \ a_N$

The $1$st line contains $N$.
The $2$nd line contains the integers written on the cards, separated by spaces.

$2 \le N \le 16$
$-9 \le a_i \le 9$

Output

Output the maximum value.

Sample

Sample 1
Input
4
0 -9 1 5
Output
50

$0 \ - \ (-9) \ + \ 1 \ × \ 5 \ = \ 50$

Sample 2
Input
8
6 6 1 3 3 2 2 -1
Output
1333

Sample 3
Input
16
6 9 1 2 1 2 1 2 1 4 1 4 1 8 1 2
Output
114514

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。