結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー nok0nok0
提出日時 2021-07-30 21:13:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 886 bytes
コンパイル時間 583 ms
コンパイル使用メモリ 86,896 KB
実行使用メモリ 143,504 KB
最終ジャッジ日時 2023-10-14 02:42:17
合計ジャッジ時間 5,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,088 KB
testcase_01 AC 72 ms
71,336 KB
testcase_02 AC 71 ms
71,068 KB
testcase_03 AC 72 ms
70,888 KB
testcase_04 AC 71 ms
71,204 KB
testcase_05 AC 73 ms
70,920 KB
testcase_06 AC 73 ms
71,088 KB
testcase_07 AC 72 ms
71,020 KB
testcase_08 AC 71 ms
71,240 KB
testcase_09 AC 73 ms
71,192 KB
testcase_10 AC 73 ms
71,292 KB
testcase_11 AC 73 ms
71,088 KB
testcase_12 AC 72 ms
71,060 KB
testcase_13 AC 73 ms
71,188 KB
testcase_14 AC 73 ms
70,888 KB
testcase_15 AC 72 ms
71,084 KB
testcase_16 AC 180 ms
120,332 KB
testcase_17 AC 175 ms
122,268 KB
testcase_18 AC 184 ms
137,316 KB
testcase_19 AC 179 ms
138,184 KB
testcase_20 AC 154 ms
128,732 KB
testcase_21 AC 153 ms
128,956 KB
testcase_22 AC 155 ms
129,004 KB
testcase_23 WA -
testcase_24 AC 161 ms
110,052 KB
testcase_25 AC 117 ms
102,356 KB
testcase_26 AC 177 ms
143,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(str, input().split())
k = list(map(int, k))
k.reverse()
n = int(n)
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))
    print("".join(res))
0