結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー U SU S
提出日時 2021-07-30 21:40:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,437 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 124,564 KB
最終ジャッジ日時 2023-10-14 03:55:13
合計ジャッジ時間 6,210 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
73,084 KB
testcase_01 AC 112 ms
73,320 KB
testcase_02 AC 115 ms
73,360 KB
testcase_03 AC 113 ms
73,028 KB
testcase_04 AC 113 ms
73,244 KB
testcase_05 AC 114 ms
73,032 KB
testcase_06 AC 114 ms
73,128 KB
testcase_07 AC 113 ms
72,960 KB
testcase_08 AC 113 ms
72,952 KB
testcase_09 AC 114 ms
73,192 KB
testcase_10 AC 112 ms
73,056 KB
testcase_11 AC 114 ms
73,356 KB
testcase_12 AC 114 ms
72,868 KB
testcase_13 AC 114 ms
72,948 KB
testcase_14 WA -
testcase_15 AC 118 ms
73,268 KB
testcase_16 AC 238 ms
123,444 KB
testcase_17 AC 237 ms
123,296 KB
testcase_18 AC 197 ms
123,196 KB
testcase_19 WA -
testcase_20 AC 179 ms
111,252 KB
testcase_21 AC 179 ms
111,140 KB
testcase_22 AC 178 ms
111,380 KB
testcase_23 AC 119 ms
74,576 KB
testcase_24 AC 231 ms
124,564 KB
testcase_25 AC 195 ms
123,232 KB
testcase_26 AC 174 ms
113,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))
import math
import bisect
from copy import deepcopy as dc
from itertools import accumulate
from collections import Counter, defaultdict, deque
import itertools
def ceil(U,V):return (U+V-1)//V
def modf1(N,MOD):return (N-1)%MOD+1
inf = int(1e10)
mod = int(1e9+7)

n,k = map(str,input().split())
n = int(n)
k = "0"*(max(n-len(k), 0)) + k
c = [0]+lmp()
ans = []
if n < len(k):
    print(-1)
    exit()
for i in range(n):
    num = int(k[i])
    if c[num] != 0 and i != n-1:
        ans.append(k[i])
        c[num] -= 1
    else:
        f = False
        for j in range(num+1, 10):
            if c[j] != 0:
                ans.append(str(j))
                c[j] -= 1
                f = True
                break
        if f:break
        else:
            l = len(ans)
            while not f:
                if not ans:
                    print(-1)
                    exit()
                t = ans.pop()
                c[int(t)] += 1
                for j in range(int(t)+1, 10):
                    if c[j] != 0:
                        ans.append(str(j))
                        c[j] -= 1
                        f = True
                        break
    #print(ans)
for i in range(1,10):
    for j in range(c[i]):
        ans.append(str(i))
print("".join(ans))






0