結果
問題 |
No.1630 Sorting Integers (Greater than K)
|
ユーザー |
|
提出日時 | 2021-07-30 21:53:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,465 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 121,800 KB |
最終ジャッジ日時 | 2024-09-15 23:55:34 |
合計ジャッジ時間 | 3,845 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 20 WA * 2 |
ソースコード
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 for i in range(1,10): for j in range(c[i]): ans.append(str(i)) if len(ans) != n: print(-1) exit() print("".join(ans))