問題一覧 > 通常問題

No.1628 Sorting Integers (MAX of M)

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 315
作問者 : とりゐ / テスター : re_re0101 👑 qand
お気に入りにしたユーザー ProblemId : 6725 / 自分の提出
問題文最終更新日: 2021-07-30 22:51:27
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 307 (順位表) の他の問題:

Problem Statement

There are $N$ positive integers of $1$ digit each. Among them, there are $c_i$ copies of $i$ $(1\leq i\leq9)$. When these $N$ integers are rearranged and the result is regarded as an $N$-digit integer $M$ in base $10$, find the maximum value among the possible values of $M$.

Input

$N$
$c_1\ c_2\ c_3\ c_4\ c_5\ c_6\ c_7\ c_8\ c_9$

  • $1\leq N\leq 9$
  • $c_i\geq0$
  • $\displaystyle \sum_{i=1}^9 c_i=N$
  • All inputs are integers.

Output

Find the maximum of all possible values of $M$.

Sample

Sample 1
Input
3
1 1 1 0 0 0 0 0 0
Output
321

Each of $1,2,3$ appears $1$ time, and the possible values of $M$ are $123,132,213,231,312,321$. Among these, $321$ is the largest.

Sample 2
Input
3
1 2 0 0 0 0 0 0 0
Output
221

The digit $1$ appears $1$ time and the digit $2$ appears $2$ times, and the possible values of $M$ are $122,212,221$. Among these, $221$ is the largest.

Sample 3
Input
1
0 1 0 0 0 0 0 0 0
Output
2

The only possible value of $M$ is $2$.

Sample 4
Input
9
1 1 1 1 1 1 1 1 1
Output
987654321

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