結果

問題 No.1630 Sorting Integers (Greater than K)
コンテスト
ユーザー chineristAC
提出日時 2021-07-30 20:47:43
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 991 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 404 ms
コンパイル使用メモリ 84,736 KB
実行使用メモリ 109,456 KB
最終ジャッジ日時 2026-04-05 02:25:42
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

def solve(N,K,c):
    if len(K) > N:
        return -1

    check_c = [0 for i in range(10)]
    for i in range(len(K)):
        check_c[int(K[i])] += 1

    for d in range(len(K)-1,-1,-1):
        check_c[int(K[d])] -= 1
        if any(c[i] < check_c[i] for i in range(10)):
            continue

        for i in range(int(K[d])+1,10):
            if c[i] > check_c[i]:
                ans = [K[:d],str(i)]
                #print(ans,check_c,c)
                c[i] -= 1
                for j in range(10):
                    c[j] -= check_c[j]
                    ans += [str(j)] * c[j]
                return "".join(ans)

    return -1

N,K = input().split()
N = int(N)
c = [0] + li()
print(solve(N,K,c))
0