結果
| 問題 |
No.1630 Sorting Integers (Greater than K)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-30 20:47:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 991 bytes |
| コンパイル時間 | 237 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 104,524 KB |
| 最終ジャッジ日時 | 2024-09-15 22:40:31 |
| 合計ジャッジ時間 | 3,980 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 WA * 1 |
ソースコード
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))