結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー nok0nok0
提出日時 2021-07-30 21:20:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 961 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 79,668 KB
最終ジャッジ日時 2023-10-14 03:09:13
合計ジャッジ時間 4,523 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 69 ms
71,096 KB
testcase_03 AC 69 ms
71,416 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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) > len(str(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