結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー nok0nok0
提出日時 2021-07-30 21:21:19
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 951 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 86,628 KB
実行使用メモリ 78,876 KB
最終ジャッジ日時 2023-10-14 03:11:44
合計ジャッジ時間 4,689 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,040 KB
testcase_01 AC 73 ms
71,084 KB
testcase_02 AC 73 ms
70,948 KB
testcase_03 AC 74 ms
70,684 KB
testcase_04 AC 71 ms
70,884 KB
testcase_05 AC 72 ms
70,904 KB
testcase_06 AC 73 ms
71,036 KB
testcase_07 AC 70 ms
70,984 KB
testcase_08 AC 73 ms
71,084 KB
testcase_09 AC 73 ms
71,024 KB
testcase_10 AC 73 ms
71,160 KB
testcase_11 AC 71 ms
71,140 KB
testcase_12 AC 74 ms
71,156 KB
testcase_13 AC 74 ms
70,980 KB
testcase_14 AC 71 ms
71,048 KB
testcase_15 AC 71 ms
70,860 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(str, input().split())
x = int(k)
k = list(map(int, k))
k.reverse()
n = int(n)
if len(k) > n:
    print(-1)
    exit()
while len(k) < n:
    k.append(0)
k.reverse()

c = list(map(int, input().split()))
co = c.copy()
pl = -1
sf = 1
for i in range(n):
    tmp = 1
    if k[i]:
        if c[k[i] - 1] == 0:
            tmp = 0
        else:
            c[k[i] - 1] -= 1
    else:
        tmp = 0

    for j in range(k[i], 9):
        if c[j]:
            pl = i
            if tmp == 0:
                c[j] -= 1
            break

    if tmp == 0:
        break

if pl == -1:
    print(-1)
else:
    res = []
    for i in range(0, pl):
        res.append(str(k[i]))
        co[k[i] - 1] -= 1
    for j in range(k[pl], 9):
        if co[j]:
            res.append(str(j + 1))
            co[j] -= 1
            break
    for i in range(9):
        for j in range(co[i]):
            res.append(str(i + 1))
    res = "".join(res)
    print(res)
0