TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
N, M = map(int, input().split())

A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

DP = [-1]*(N+1)
DP[0] = 0 

for i in range(N):
    for j in A:
        if i+B[j] <= N:
            DP[i+B[j]] = max(DP[i]*10+j, DP[i+B[j]])

print(DP[N+1]) 

N, M = map(int, input().split())

A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

DP = [-1]*(N+1)
DP[0] = 0 

for i in range(N):
    for j in A:
        if i+B[j] <= N:
            DP[i+B[j]] = max(DP[i]*10+i,DP[i+B[j]])

print(DP[N+1]) 

N, M = map(int, input().split())

A = list(map(int, input().split()))
B = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

DP = [-1]*(N+1)
DP[0] = 0 

for i in range(N):
    for j in A:
        if i+B[j] <= N:
            DP[i+B[j]] = max(DP[i]*10+j, DP[i+B[j]])

print(DP[N]) 

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):

from heapq import heappop, heappush
N, M = map(int, input().split())
A = list(map(int, input().split()))

queue = []

for a in A:
  if a == 1:
    heappush(queue, (2, 1))
  elif a == 2:
    heappush(queue, (5, 2))
  elif a == 3:
    heappush(queue, (5, 3))
  elif a == 4:
    heappush(queue, (4, 4))
  elif a == 5:
    heappush(queue, (5, 5))
  elif a == 6:
    heappush(queue, (6, 6))
  elif a == 7:
    heappush(queue, (3, 7))
  elif a == 8:
    heappush(queue, (7, 8))
  elif a == 9:
    heappush(queue, (6, 9))

x, y = heappop(queue)
mod = N % x
ans = [y] * ((N - N % x) // x)
baseX = x

while mod != 0:
  ans = ans[1:]
  mod += baseX
  x, y = heappop(queue)
  ans.append(y)
  mod %= x

for a in sorted(ans, reverse=True):
  print(a, end="")

N,M = map(int,input().split())
A = list(map(int,input().split()))
weight = [0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)
dp[0] = 0

for i in range(N+1):
  if dp[i] == -1: continue
  for a in A:
    if i+weight[a]<N+1:
      dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)
      print(dp)

print(dp[-1])


N, M = map(int, input().split())
A = list(map(int, input().split()))
numbers = [0,2,5,5,4,5,6,3,7,6]


dp = ["-" for i in range(11000)]
dp[0] = ""

def cal(x, y):
  lenx = len(x)
  leny = len(y)
  
  if lenx > leny:
    return x
  if leny > lenx:
    return y
  
  return max(x, y)

for i in range(N):
  if dp[i] == "-": 
    continue

  for j in range(M):
    num = numbers[A[j]]
    dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num])

print(dp[N])

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
N, M = map(int, input().split())
*A, = map(int, input().split())

dp = [""] * (N+1)
d = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6
}

c = [(i, d[i]) for i in A]
c.sort(key=lambda x:(-x[1], -x[0]))
dp[0] = ""
dp[1] = ""

for i in range(2, N+1):
    for n, cost in c:
        if i-cost<0: continue
        a = int(dp[i]) if dp[i] else 0
        b = int(str(n) + dp[i-cost])
        if a<b:
            dp[i] = str(n) + dp[i-cost]

a = 0
for s in dp[N]:
    a+= d[int(s)]

if a==N:
    print(dp[N])

n,m=map(int,input().split())
*a,=map(int,input().split())

cost={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[-1]*(n+1)
v=[0]*(n+1)

dp[0]=0
for i in range(1,n+1):
    for j in range(10)[::-1]:
        if not j in a or i<cost[j]:continue
        if dp[i]<dp[i-cost[j]]+1:
            dp[i]=dp[i-cost[j]]+1
            v[i]=j

p=n
while p!=0:
    print(v[p],end="")
    p-=cost[v[p]]
print()

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
from collections import defaultdict
from itertools import product, permutations, combinations, combinations_with_replacement

N, M = map(int, input().split())
A = list(map(int, input().split()))
L = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
D = defaultdict(int)

for i in A:
  if D[L[i]] < i:
    D[L[i]] = i

Nums = sorted((D.keys()))

sup = N//Nums[0]
E = defaultdict(int)
Flag = False

for i in range(Nums[-1]):
  base = (max(sup-Nums[-1], 0) + i) * Nums[0]
  if base == N:
    E[Nums[0]] += sup-i
    break
  for cwr in combinations_with_replacement([0]+Nums[1:], Nums[0]):
    if base + sum(cwr) == N:
      E[Nums[0]] += sup-i
      for j in cwr:
        if j != 0:
          E[j] += 1
      Flag = True
      break
  if Flag:
    break

ans = ""
for i, x in E.items():
  ans += str(D[i])*x

print(*sorted(list(ans), reverse=True), sep="")

from collections import defaultdict
from itertools import product, permutations, combinations, combinations_with_replacement

N, M = map(int, input().split())
A = list(map(int, input().split()))
L = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
D = defaultdict(int)

for i in A:
  if D[L[i]] < i:
    D[L[i]] = i

Nums = sorted((D.keys()))

sup = N//Nums[0]
E = defaultdict(int)
Flag = False

for i in range(Nums[-1]):
  base = (max(sup-Nums[-1]+1, 0) + i) * Nums[0]
  if base == N:
    E[Nums[0]] += sup-i
    break
  for cwr in combinations_with_replacement([0]+Nums[1:], Nums[0]):
    if base + sum(cwr) == N:
      E[Nums[0]] += sup-i
      for j in cwr:
        if j != 0:
          E[j] += 1
      Flag = True
      break
  if Flag:
    break

ans = ""
for i, x in E.items():
  ans += str(D[i])*x

print(ans, D, Nums, E)
print(*sorted(list(ans), reverse=True), sep="")

from collections import defaultdict

N, M = map(int, input().split())
A = list(map(int, input().split()))
L = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
D = defaultdict(int)

for i in A:
  if D[L[i]] < i:
    D[L[i]] = i

INF = float("inf")
dp = [-INF]*(N+1)
dp[0] = 0

for i in range(1, N+1):
  for j in D.keys():
    if i-j >= 0:
      dp[i] = max(dp[i], dp[i-j] + 1)
    else:
      dp[i] = max(dp[i], -INF)

ans = ""
temp = N


for i, x in sorted(D.items(), key=lambda x: x[1], reverse=True):
  while temp - i >= 0 and dp[temp-i] == dp[temp] - 1:
    ans += str(x)
    temp -= i

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**9)

N,M=map(int,input().split())
A=list(map(int,input().split()))
M=[0,2,5,5,4,5,6,3,7,6]

def match(i):
    ANS=0
    for s in str(i):
        ANS+=M[int(s)]

    return ANS
        
ANSLIST=set()
def dfs(i,NOW):
    if NOW==N:
        L=sorted(list(i),reverse=True)
        
        x=int(("".join(L)))
        ANSLIST.add(x)

        if len(ANSLIST)>=500:
            #print(ANSLIST)
            print(max(ANSLIST))
            sys.exit()
    elif NOW>N:
        return
    else:
        for a in A:
            dfs(i+str(a),NOW+M[a])


A.sort(reverse=True)
#print(A)
A.sort(key=lambda x:M[x])
#print(A)

dfs("",0)

import sys
sys.setrecursionlimit(10**9)

N,M=map(int,input().split())
A=list(map(int,input().split()))
M=[0,2,5,5,4,5,6,3,7,6]



SET_A=set(A)

ANSLIST=[0]
def dfs(i,NOW):
    if ANSLIST[0]!=0:
        return
    ANS=0
    if NOW==N:
        L=sorted(list(i),reverse=True)
        #print(L)
        
        ANSLIST[0]=int(("".join(L)))
        return

    elif NOW>N:
        return 
    else:
        for a in A:
            dfs(i+str(a),NOW+M[a])


A.sort(reverse=True)
A.sort(key=lambda x:M[x])
dfs("",0)

x=ANSLIST[0]
stx=str(x)
from collections import Counter
counter=Counter(stx)


import itertools
for i,j,k in list(itertools.combinations(range(1,10),3)):
    for l,m,n in list(itertools.combinations(range(1,10),3)):
        if i in SET_A and j in SET_A and k in SET_A and l in SET_A and m in SET_A and n in SET_A and M[i]+M[j]+M[k]==M[l]+M[m]+M[n] and \
           counter[str(i)]>0 and counter[str(j)]>0 and counter[str(k)]>0 and (n>k or (n==k and m>j) or (n==k and m==j and l>i)):
                    x=min(counter[str(i)],counter[str(j)],counter[str(k)])
                    counter[str(i)]-=x
                    counter[str(j)]-=x
                    counter[str(k)]-=x
                    counter[str(l)]+=x
                    counter[str(m)]+=x
                    counter[str(n)]+=x

for i,j in list(itertools.combinations(range(1,10),2)):
    for l,m in list(itertools.combinations(range(1,10),2)):
        if i in SET_A and j in SET_A and l in SET_A and m in SET_A and M[i]+M[j]==M[l]+M[m] and \
           counter[str(i)]>0 and counter[str(j)]>0 and (m>j or (m==j and l>i)):
                    x=min(counter[str(i)],counter[str(j)])
                    counter[str(i)]-=x
                    counter[str(j)]-=x

                    counter[str(l)]+=x
                    counter[str(m)]+=x

for i in range(1,10):
    for l in range(1,10):
        if i in SET_A and l in SET_A and l>i and M[i]==M[l] and counter[str(i)]>0:
            counter[str(l)]+=counter[str(i)]
            counter[str(i)]=0



ANS=""
for i in range(9,-1,-1):
    ANS+=str(i)*counter[str(i)]

print(ANS)



Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
N, M = map(int, input().split())
A = list(map(int, input().split()))

tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A_cmp = {}
for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai
A = list(A_cmp.values())
A = A[::-1]
# print("#", A)

memo = [None] * (N + 1)
memo[0] = 0

import sys
sys.setrecursionlimit(100000)

def dp(X):
    if memo[X] != None: return memo[X]
    if X < 0: return -(1000000007)
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret

ans_len = dp(N)

N_tmp = N
ans = ''
for i in range(ans_len):
    for j, Aj in enumerate(A):
        if j < j_str: continue
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break

print(ans)


N, M = map(int, input().split())
A = list(map(int, input().split()))

tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A_cmp = {}
for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai
A = list(A_cmp.values())
A.sort(key=lambda x: -x)

memo = [None] * (N + 1)
memo[0] = 0

import sys
sys.setrecursionlimit(100000)

def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret

ans_len = dp(N)

N_tmp = N
ans = ''
for i in range(ans_len):
    for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break

print(ans)

Verdicts: Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
n,m,*a=map(int,open(0).read().split())
d=[0]*n*9
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print(d[n])

n,m,*a=map(int,open(0).read().split())
d=[0]*n*9
for i in range(n):
 for j in a:c=i+(0,2,5,5,4,5,6,3,7,6)[j];d[c]=max(d[c],(d[i]*10+j)*(d[i]or i<1))
print(d[n])

n,m,*a=map(int,open(0).read().split())
d=[0]+[-1]*n*9
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print(d[n])

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
# ABC 118 D

def resolve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

    dp = [0] * (N+1)
    for i in range(1, N+1):
        for a in A:
            if i - costs[a] < 0:
                continue
            dp[i] = max(dp[i-costs[a]] + 1, dp[i])

    ans = ""
    remain = dp[N]
    match = N

    while match > 0:
        for a in A:
            if match - costs[a] < 0 or match - costs[a] == 1:
                continue

            if dp[match-costs[a]] == remain-1:
                ans += str(a)
                match -= costs[a]
                remain -= 1
                break

    print(ans)


if __name__ == "__main__":
    resolve()


# ABC 118 D

def resolve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse=True)

    costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

    dp = [-1] * (N+1)
    dp[0] = 0
    for i in range(1, N+1):
        for a in A:
            if i - costs[a] < 0:
                continue
            dp[i] = max(dp[i-costs[a]] + 1, dp[i])

    ans = ""
    remain = dp[N]
    match = N

    minCosts = 10
    for a in A:
        minCosts = min(minCosts, costs[a])

    while match > 0:
        for a in A:
            if match - costs[a] < 0 or 1<= match - costs[a] < minCosts:
                continue

            if dp[match-costs[a]] == remain-1:
                ans += str(a)
                match -= costs[a]
                remain -= 1
                break

    print(ans)


if __name__ == "__main__":
    resolve()


Verdicts: Time Limit Exceeded

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
from collections import defaultdict
from copy import copy

N,M = map(int,input().split())
A = list(map(int,input().split()))

ms = [2,5,5,4,5,6,3,7,6]
dic = defaultdict(lambda: 0)
for a in A:
    dic[ms[a-1]] = max(dic[ms[a-1]], a)

sd = sorted(dic.items())

dp = [None] * (N+1)
dp[0] = defaultdict(lambda: 0)

for i in range(sd[0][0], N+1):
    cands = []
    for l,a in sd:
        if i-l < 0: break
        if dp[i-l] is None: continue
        cands.append(copy(dp[i-l]))
        cands[-1][a] += 1
    if not cands: continue
    max_v = 0
    max_i = -1
    for i,cand_dic in enumerate(cands):
        tmp_s = ''
        for a,n in sorted(cand_dic.items(), reverse=True):
            tmp_s += str(a) * n
        tmp_v = int(tmp_s)
        if tmp_v > max_v:
            max_v = tmp_v
            max_i = i
    dp[i] = cands[i]

ans = ''
for a,n in sorted(dp[-1].items(), reverse=True):
    ans += str(a) * n
print(ans)

from collections import defaultdict
from copy import copy

N,M = map(int,input().split())
A = list(map(int,input().split()))

ms = [2,5,5,4,5,6,3,7,6]
dic = defaultdict(lambda: 0)
for a in A:
    dic[ms[a-1]] = max(dic[ms[a-1]], a)

sd = sorted(dic.items())

dp = [None] * (N+1)
dp[0] = defaultdict(lambda: 0)

for i in range(sd[0][0], N+1):
    cands = []
    least_len = -1
    for l,a in sd:
        if i-l < 0: break
        if dp[i-l] is None: continue
        if cands and sum(dp[i-l].values())+1 < least_len:
            continue
        cands.append(copy(dp[i-l]))
        cands[-1][a] += 1
        least_len = sum(cands[-1].values())
    if not cands: continue
    max_v = 0
    max_j = -1
    for j,cand_dic in enumerate(cands):
        tmp_s = ''
        for a,n in sorted(cand_dic.items(), reverse=True):
            tmp_s += str(a) * n
        tmp_v = int(tmp_s)
        if tmp_v > max_v:
            max_v = tmp_v
            max_j = j
    dp[i] = cands[max_j]

ans = ''
for a,n in sorted(dp[-1].items(), reverse=True):
    ans += str(a) * n
print(ans)

Verdicts: Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
n,m=map(int,input().split())
A=reversed(sorted(map(int,input().split())))
M=[2,5,5,4,5,6,3,7,6]
D={}
E={}
for a in A:
    if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1]
S=list(reversed(sorted(E)))
        
dp=[0]*(n+2)
for i in range(1,n+2):
    cnt=-1
    for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
    dp[i]=cnt    
k=dp[n]
ans=""


print(dp)
while k>0:
    for s in S:
        x=E[s]
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break
print(ans)

n,m=map(int,input().split())
A=reversed(sorted(map(int,input().split())))
M=[2,5,5,4,5,6,3,7,6]
D={}
E={}
for a in A:
    if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1]
S=list(reversed(sorted(E)))
        
dp=[0]*(n+2)
for i in range(1,n+2):
    cnt=-1
    for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
    dp[i]=cnt    
k=dp[n]
ans=""
print(E)

while k>0:
    for s in S:
        x=E[s]
        if n-x<0:
            continue
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break
print(ans)

n,m=map(int,input().split())
A=reversed(sorted(map(int,input().split())))
M=[2,5,5,4,5,6,3,7,6]
D={}
E={}
for a in A:
    if M[a-1] in D:
        continue
    else:
        D[M[a-1]]=a
        E[a]=M[a-1]
S=list(reversed(sorted(E)))
        
dp=[0]*(n+2)
for i in range(1,n+2):
    cnt=-1
    for d in D:
        if i-d>=0:
            if dp[i-d]!=-1:
                cnt=max(dp[i-d]+1,cnt)
    dp[i]=cnt    
k=dp[n]
ans=""

while k>0:
    for s in S:
        x=E[s]
        if n-x<0:
            continue
        if dp[n-x]==k-1:
            ans+=str(s)
            k-=1
            n-=x
            break
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
cost=[0,2,5,5,4,5,6,3,7,6]
N,M=map(int,input().split())
A=sorted(map(int,input().split()))
lowcost_i=A[0];lowcost=cost[A[0]]
for a in A:
    if cost[a]<lowcost:lowcost_i=a;lowcost=cost[a]
s=str(lowcost_i)*(N//lowcost)
l=N%lowcost
before_l=l
disit=0

while l>0:
    lll = {a:cost[a] for a in A if cost[a]<=l+lowcost}
    mmm = max(lll.keys())
    if mmm>lowcost_i:
        #print("p")
        s=s[:disit]+str(mmm)+s[disit+1:]
        l-=lll[mmm]-lowcost
        disit+=1
    else:
        #print("E")
        for k in sorted(lll.keys())[::-1]:
            if lll[k]==l+lowcost:
                s=s[:len(s)]+str(k)
                l=0
                break
    #print(s)

print(s)

c=[0,2,5,5,4,5,6,3,7,6]
I=lambda:map(int,input().split())
N,M=I()
A=sorted(I())[::-1]
d=[0]
for i in range(N):l=[d[i+1-c[a]]for a in A if i+2>c[a]];d+=[-1 if len(l)==0 else max(l)+1]
S=''
T=0
for i in range(d[N]):
 for a in A:
  b=c[a]
  if N-T-b>=0 and d[N-T-b]==d[N]-1-i:S+=str(a);T+=b;break
print(S)

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
from operator import itemgetter
tik = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[8,7],[6,6]]
dic = {"1":2,"7":3,"4":4,"5":5,"3":5,"2":5,"9":6,"8":7,"6":6}

n,k = map(int, input().split())
x = list(map(int, input().split()))
dp = [0]+[-1]*(n+10)
q = []
for i in range(k):
    q.append([x[i],dic[str(x[i])]])

q = sorted(q, key=itemgetter(1), reverse=False)

s = []
p=0
t = 0
for i in range(n):
    for j in range(k):
        if i+q[j][1] <=n:
            if dp[i]!=-1:
            
                if  dp[i]==0:
                    ko = str(q[j][0])
                    dp[i+q[j][1]] = max(str(q[j][0]),str(dp[i+q[j][1]]))

                else:
                    ko = str(dp[i])+str(q[j][0])
                    dp[i+q[j][1]] = max(str(dp[i])+str(q[j][0]), str(dp[i+q[j][1]]))
        #if i+q[j][1] ==n:
            #print(dp[20])
s = list(dp[n])
s.sort()
s = s[::-1]
print(''.join(s))


from operator import itemgetter
tik = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[8,7],[6,6]]
dic = {"1":2,"7":3,"4":4,"5":5,"3":5,"2":5,"9":6,"8":7,"6":6}

n,k = map(int, input().split())
x = list(map(int, input().split()))
dp = [0]+[-1]*(n+10)
q = []
for i in range(k):
    q.append([x[i],dic[str(x[i])]])

q = sorted(q, key=itemgetter(1), reverse=False)

s = []
p=0
t = 0
for i in range(n):
    for j in range(k):
        if i+q[j][1] <=n:
            if dp[i]!=-1:
            
                if  dp[i]==0:
                    ko = str(q[j][0])
                    dp[i+q[j][1]] = min(str(q[j][0]),str(dp[i+q[j][1]]))

                else:
                    ko = str(dp[i])+str(q[j][0])
                    dp[i+q[j][1]] = min(str(dp[i])+str(q[j][0]), str(dp[i+q[j][1]]))
        #if i+q[j][1] ==n:
            #print(dp[20])
s = list(dp[n])
s.sort()
s = s[::-1]
print(''.join(s))


from operator import itemgetter
tik = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[8,7],[6,6]]
dic = {"1":2,"7":3,"4":4,"5":5,"3":5,"2":5,"9":6,"8":7,"6":6}

n,k = map(int, input().split())
x = list(map(int, input().split()))
dp = [0]+[-1]*(n+10)
q = []
for i in range(k):
    q.append([x[i],dic[str(x[i])]])

q = sorted(q, key=itemgetter(1), reverse=False)

s = []
p=0
t = 0
for i in range(n):
    for j in range(k):
        if i+q[j][1] <=n:
            if dp[i]!=-1:
            
                if  dp[i]==0:
                    ko = q[j][0]
                    dp[i+q[j][1]] = max(q[j][0],dp[i+q[j][1]])

                else:
                    ko = dp[i]+q[j][0]
                    dp[i+q[j][1]] = max(dp[i]*10+q[j][0], dp[i+q[j][1]])
        #if i+q[j][1] ==n:
            #print(dp[20])
s = list(str(dp[n]))
s.sort()
s = s[::-1]
print(''.join(s))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
n,m = map(int,input().split())
l = [2,5,5,4,5,6,3,7,6]
A = list(map(int, input().split()))
mina = [0,9]
for a in A:
    if l[a-1] < mina[1]:
        mina[0] = a
        mina[1] = l[a-1]
    elif l[a-1] == mina[1] and mina[0] < a:
        mina[0] = a
    else:
        continue
keta = n // mina[1]
k = keta
A.sort(reverse=True)
anslist = [mina[0]]*(keta)
for i in range(keta):
    k -= 1
    for a in A:
        if n-l[a-1]>=k*mina[1]:
            n -=l[a-1]
            anslist[i]=a
            break
        else:
            continue
ans = list(map(str,anslist))
print("".join(ans))

n,m= map(int,input().split())
A = list(map(int,input().split()))
cost = [0,2,5,5,4,5,6,3,7,6]
dp =[-1]*10010
dp[0]=0
for i in range(1,n+1):
    for a in A:
        if i - cost[a] >= 0:
            dp[i] = max(dp[i],a+dp[i-cost[a]]*10)
print(dp[n])

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
num = [(i, num[i]) for i in range(10) if i in A]
num.sort(key=lambda x: x[0], reverse=True)
num.sort(key=lambda x: x[1])
dp = ["" for i in range(N+1)]
ans = 0
tmp = set()
for x in num:
    if x > N:
        continue
    for i in range(1, N+1-x[1]):
        for n, k in num:
            if i - k in tmp:
                dp[i] = dp[i-k]+str(n)
                tmp.add(i)
                break
            else:
                if i == k:
                    dp[i] = str(n)
                    tmp.add(k)
                    break
    tmp2 = list(dp[N-x[1]])
    tmp2.append(str(x[0]))
    tmp2.sort(reverse=True)
    ans = max(int("".join(map(str, tmp2))), ans)
print(ans)


def main():
    N, M = map(int, input().split())
    A = set(map(int, input().split()))


    cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    B = []
    for i in range(1, 10):
        if i in A:
            B.append((cost[i], i))

    B = B[::-1]
    dp = [[-1, -1] for i in range(N+1)]
    dp[0][0] = 0
    for i in range(1, N+1):
        for x, y in B:
            if i >= x and dp[i-x][0] >= 0:
                if dp[i][0] < dp[i-x][0] + 1:
                    dp[i][0] = dp[i-x][0] + 1
                    dp[i][1] = y
    id = N
    ans = []
    # print(dp)
    while(id > 0):
        ans.append(dp[id][1])
        id -= cost[dp[id][1]]
    ans.sort(reverse=True)
    print("".join(map(str, ans)))
main()

Verdicts: Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split())
a = list(map(int, input().split()))
cost = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [None] * (n + 1)
def dfs(at):
    if dp[at] is not None:
        return dp[at]
    r = max([0] + [dfs(at - cost[v]) * 10 + v for v in a if at - cost[v] >= 0])
    dp[at] = r
    return r


print(dfs(n))


import sys
sys.setrecursionlimit(1000000)

n, m = map(int, input().split())
a = list(map(int, input().split()))
cost = [float("inf"), 2, 5, 5, 4, 5, 6, 3, 7, 6]
mincost = min(cost)

dp = [None] * (n + 1)
def dfs(at):
    if at < 0:
        return -1
    if at == 0:
        return 0
    if dp[at] is not None:
        return dp[at]
    r = max(dfs(at - cost[v]) * 10 + v for v in a)
    dp[at] = r
    return r


print(dfs(n))


Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
import os, sys, re, math

N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
print(A)

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]

    max_v = 0
    for a in A:
        if m - match[a] == 0:
            max_v = max(int(max_v), int(str(a)))
        elif m > match[a]:
            tmp = doit(m - match[a])
            if tmp != '0':
                max_v = max(int(max_v), int(str(a) + doit(m - match[a])))

    memo[m] = str(max_v)
    return str(max_v)

print(doit(N))


import os, sys, re, math

N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
print(A)

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]

    max_v = '-9'
    for a in A:
        if m - match[a] == 0:
            max_v = max(max_v, str(a), key=lambda x: int(x))
        elif m - match[a] >= 0:
            max_v = max(max_v, doit(m - match[a]) + str(a), key=lambda x: int(x))
    if max_v != '':
        memo[m] = str(max_v)
        return str(max_v)
    else:
        return '-9'

print(doit(N))


import os, sys, re, math

N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))
print(A)

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m <= 0:
        return ''

    max_v = '0'
    for a in A:
        tmp = doit(m - match[a])
        if m >= match[a] and tmp is not None:
            max_v = max(max_v, str(a) + doit(m - match[a]),key= lambda x: int(x))

    if max_v != '0':
        memo[m] = max_v
        return max_v
    else:
        return None

print(doit(N))


import os, sys, re, math
sys.setrecursionlimit(100000)
N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))

match = [100,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = str(a) + tmp
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
N, M = map(int, input().split())
A = list(map(int, input().split()))
weight = [0,2,5,5,4,5,6,3,7,6]
inf = float('inf')
dp = [-inf] * (N+1)
dp[0] = 0
for i in range(N+1):
    for a in A:
        if i + weight[a] < N+1:
            dp[i + weight[a]] = max(dp[i + weight[a]], dp[i]*10 + a)
print(dp)


N, M = map(int, input().split())
A = list(map(int, input().split()))
weight = [0,2,5,5,4,5,6,3,7,6]
dp = [-1] * (N+1)
dp[0] =  0

for i in range(N+1):
    for a in A:
        if i + weight[a] < N+1:
            dp[i + weight[a]] = max(dp[i + weight[a]], dp[i]*10 + a)
print(dp[-1])


Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
a,b=list(map(int,input().split()))
X={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
A=list(map(int,input().split()))
B=[v for k,v in X.items() if k in A]
print(B)
DP=[0]+[[] for i in range(10**4+1)]
L=[[] for i in range(10**4+1)]
for i in range(10):
    if i in B:
        DP[i]=1
        L[i].append(i)
#print(DP)
for i in range(1,10**4+1):
    if [DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]]==[]:
        DP[i]=[]
    else:
#        print(i,[DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]])
        M=[DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]]
        DP[i]=max([DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]])+1
        l=[0]
        for t in B:
            if not DP[i-t]==[] and DP[i]==DP[i-t]+1:
                l=l+[k for k,v in X.items() if v==t and k in A]
                L[i]=L[i-t]+[max(l)]
L[a].sort(reverse=True)
s='0'
for i in L[a]:
    s+=str(i)
print(int(s))

a,b=list(map(int,input().split()))
X={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
A=list(map(int,input().split()))
B=[v for k,v in X.items() if k in A]

DP=[0]+[[] for i in range(10**4+1)]
L=[[] for i in range(10**4+1)]
for i in range(10):
    if i in B:
        DP[i]=1
        L[i].append(i)
#print(DP)
for i in range(1,10**4+1):
    if [DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]]==[]:
        DP[i]=[]
    else:
#        print(i,[DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]])
        M=[DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]]
        DP[i]=max([DP[i-j] for j in B if i-j>=0 and not DP[i-j]==[]])+1
        l=[0]
        for t in B:
            if not DP[i-t]==[] and DP[i]==DP[i-t]+1:
                l=l+[k for k,v in X.items() if v==t and k in A]
                L[i]=L[i-t]+[max(l)]
L[a].sort(reverse=True)
s='0'
for i in L[a]:
    s+=str(i)
print(int(s))

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
nn=[[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[6,6],[8,7]]
n,m=map(int,input().split())
a=input().split()
for i in range(m):
  a[i]=int(a[i])
b=[]
for i in range(9):
  if nn[i][0] in a:
    b.append(nn[i])
  
c=[b[0]]
del b[0]
for i in range(len(b)):
  t=0
  for j in range(len(c)):
    if b[i][1] == c[j][1]:
      t=1
      break
  if t==1:
    continue
  c.append(b[i])
  
t=n//c[0][1]
n-=c[0][1]*t
a=c[0]
del c[0]
for i in range(len(c)):
  c[i][1]-=a[1]

ans=""
while c[0][1] <= n:
  for i in range(len(c)):
    i=len(c)-1-i
    if c[i][1]<=n:
      ans+=str(c[i][0])
      n-=c[i][1]
      t-=1
      break
      
ans+=str(a[0])*t
print(ans)

nn=[2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
a=input().split()
b=[]
for i in range(m):
  a[i]=int(a[i])
  
if 5 in a:
  if 2 in a:
    a.remove(2)
  if 3 in a:
    a.remove(3)
elif 3 in a:
  if 2 in a:
    a.remove(2)
if 9 in a:
  if 6 in a:
    a.remove(6)
    
a.sort(reverse=True)
for i in range(len(a)):
  b.append(nn[a[i]-1])
  
dp=[-10*18 for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(len(b)):
    if i+b[j]>n-1:
      continue
    dp[i+b[j]]=max(dp[i+b[j]],dp[i]+1)
    
k=dp[n-1]
ans=""
for i in range(k):
  for j in range(len(b)):
    if dp[n-1-b[j]]==dp[n-1]-1:
      ans+=str(a[j])
      n-=b[j];
      break
      
print(ans)



nn=[2,5,5,4,5,6,3,7,6]
n,m=map(int,input().split())
a=input().split()
b=[]
for i in range(m):
  a[i]=int(a[i])
  
if 5 in a:
  if 2 in a:
    a.remove(2)
  if 3 in a:
    a.remove(3)
elif 3 in a:
  if 2 in a:
    a.remove(2)
if 9 in a:
  if 6 in a:
    a.remove(6)
    
a.sort(reverse=True)
for i in range(len(a)):
  b.append(nn[a[i]-1])
  
dp=[-10*18 for _ in range(n+1)]
dp[0]=0
for i in range(n):
  for j in range(len(b)):
    if i+b[j]>n:
      continue
    dp[i+b[j]]=max(dp[i+b[j]],dp[i]+1)
    
k=dp[n]
ans=""
for i in range(k):
  for j in range(len(b)):
    if n-b[j]<0:
      continue
    if dp[n-b[j]]==dp[n]-1:
      ans+=str(a[j])
      n-=b[j]
      break
      
print(ans)



Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N==2, and M==9:
    print(1)
    exit()

dp = [0]+[-INF]*N

for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins


A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))


N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N,M = 2,9:
    print(1)
    exit()

dp = [0]+[-INF]*N

for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins


A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))


N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
INF = float("inf")
num = [INF,2,5,5,4,5,6,3,7,6]
if N==2 and M==9:
    print(1)
    exit()

dp = [0]+[-INF]*N

for i in range(1,N+1):
    ins = -INF
    for a in A:
        try:
            tmp = dp[i-num[a]]+1
            ins = max(ins,tmp)
        except:
            continue
    dp[i] = ins


A.sort(reverse=True)
digit = ["0"]*dp[N]
mat = 0
for i in range(dp[N]):
    for a in A:
        try:
            t1 = dp[N-mat-num[a]]
            t2 = dp[N-mat]-1
        except:
            continue
        if t1 == t2:
            digit[i] = str(a)
            mat += num[a]
            break
print("".join(digit))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
def intlog10(n):
    if n <= 0:
        return -1
    i = 0
    while 10**i <= n:
        i += 1
    return i-1

N, M = map(int, input().split())
A = [int(a) for a in input().split()]
if True:
    N = 10000
    M = 9
    A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]



best = sorted(B, key = lambda x: x[1]*10-x[0])[0]

adj = 0
if N > 500:
    adj = (N - 500)//best[1]
    N -= best[1] * adj



# print(best)
X = [0] + [-10**9] * N
bpre = -1
ll = 1
for i in range(1, N+1):
    if i > 50 and i < N-50:
        X[i] = X[i-best[1]]*10 + best[0]
    else:
        for b in B:
            if b[1] <= i:
                if X[i-b[1]] == 0:
                    if b[0] > X[i]:
                        X[i] = b[0]
                        bpre = b
                        ll = 0
                else:
                    if X[i-b[1]]*10 + b[0] < X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])):
                        lll = 1

                    if max(X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]]))) > X[i]:
                        X[i] = max(X[i-b[1]]*10 + b[0], X[i-b[1]] + b[0] * (10**intlog10(X[i-b[1]])))
                        ll = lll
                        bpre = b
                

ans = str(X[N])
if adj > 0:
    ans = ans[:50] + str(best[0]) * adj + ans[50:]

print(ans)
# print(len(ans))

N, M = map(int, input().split())
A = [int(a) for a in input().split()]    
L = [2, 5, 5, 4, 5, 6, 3, 7, 6]
B = [[A[i], L[A[i]-1]] for i in range(M)]

X = [0] + [-1] * N
for i in range(1, N+1):
    for b in B:
        if b[1] <= i:
            X[i] = max(X[i], X[i-b[1]]*10 + b[0])

print(X[N])

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
N,M=map(int, input().split())
A=list(map(int, input().split()))
inf = float('inf')

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if dp[N] == dp[N-number[j]] + 1:
      ans += str(j)
      N -= number[j]
      break

print(int(ans))

import sys
import math
import copy

input = sys.stdin.readline
N,M=map(int,input().split())
A=list(map(int, input().split()))

match_num=[6,2,5,5,4,5,6,3,7,6]
use_A_dict = {}
for a in A:
  if a in use_A_dict.values():
    use_A_dict[match_num[a]] = max(a,use_A_dict[match_num[a]])
  else:
    use_A_dict[match_num[a]] = a

match = list(use_A_dict.keys())
match.sort()
number = [use_A_dict[m] for m in match]
use_num = [0]*len(number)
current_use_num = [-1]*len(number)
use_num_cand = []
N_left = N
index = -1
use_num_sum = 0
finish_flag = 0
while finish_flag == 0:
  index += 1
  if index < len(number):
    use_num[index] = math.floor(N_left/match[index])
    N_left = N_left % match[index]
    if N_left == 0:
      if use_num_sum <= sum(use_num):
        if use_num != current_use_num:
          use_num_cand.append(copy.deepcopy(use_num))
          use_num_sum = sum(use_num)
          current_use_num = copy.deepcopy(use_num)
      else:
        finish_flag = 1
  else:
    index -= 1
    while use_num[index] == 0:
      if index != 0:
        index -= 1
      else:
        finish_flag = 1
        break
    use_num[index] -= 1
    N_left += match[index]

ans_cand = []
ans_list = []
print(use_num_cand)
for j in range(len(use_num_cand)):
  ans_list = []
  for i in range(len(number)):
    ans_list.extend([number[i]]*use_num_cand[j][i])
  ans_list.sort(reverse=True)
  ans = ""
  for i in ans_list:
    ans += str(i)
  ans_cand.append(int(ans))
print(max(ans_cand))

N,M=map(int, input().split())
A=list(map(int, input().split()))
inf = float('inf')

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1
        dp_new = dp[i]

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if N - number[j] >= 0:
      if dp[N] == dp[N-number[j]] + 1:
        ans += str(j)
        N -= number[j]
        break

print(int(ans))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
import numpy as np

costs=np.array([6,2,5,5,4,5,6,3,7,6],dtype=np.int)

(N,M) = map(int,input().split())
A = np.array(list(map(int,input().split())))

cost_table = np.vstack((costs[A],A)).transpose()
tb1=np.array(sorted(list(cost_table),key=lambda x:(x[0],-x[1])))
tb2=np.array(sorted(list(cost_table),key=lambda x:(-x[1],x[0])))

c = tb1[0,0]
d = tb1[0,1]
tb1[:,0] -= c
tb2[:,0] -= c

n = N // c
r = N % c

dd = np.ones(n,dtype=np.int)*d

upperlist=[]
lowerlist=[]
while r > 0:
    k = np.where(tb2[:,0] <= r)[0][0]
    if tb2[k,1] > d:
        upperlist.append(tb2[k,1])
        r -= tb2[k,0]
    else:
        k = np.where(tb1[:,0] <= r)[0][-1]
        lowerlist.append(tb1[k,1])
        r -= tb1[k,0]

for u in upperlist:
    print(u,end='')
for i in range(n-len(lowerlist)-len(upperlist)):
    print(dd[i],end='')
for u in lowerlist:
    print(u,end='')


import numpy as np

(N,M) = map(int,input().split())
A = list(map(int,input().split()))
costs = [0,2,5,5,4,5,6,3,7,6]

match = [-1]*(N+1)
match[0] = 0
for i in range(1,N+1):
  for a in A:
    if i < costs[a]:
      continue
    else:
      match[i] = max(match[i],match[i-costs[a]]*10+a)

print(match[N])

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0,2,5,5,4,5,6,3,7,6]
wv=[]
for i in a:
  wv.append((b[i],i))
wv.sort()
dp=[-1 for i in range(n+1)]
dp[0]=0
for i in range(1,n+1):
  for w,v in wv:
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v)

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[0,2,5,5,4,5,6,3,7,6]
wv=[]
for i in a:
  wv.append((b[i],i))
wv.sort()
dp=[-1 for i in range(n+1)]
dp[0]=0
for i in range(1,n+1):
  for w,v in wv:
    if i-w<0:
      continue
    if dp[i-w]==-1:
      continue
    dp[i]=max(dp[i],dp[i-w]*10+v)
print(dp[n])

Verdicts: Runtime Error

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
import time
n, m = map(int, input().split())
numbers = list(map(int, input().split()))
costs = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010
f[0] = 0
for i in range(1, n+1):
    for x in numbers:
        if i-costs[x] >= 0:
            f[i] = max(f[i], f[i-costs[x]]*10+x)
print(f)

import time
n, m = map(int, input().split())
numbers = list(map(int, input().split()))
costs = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010
f[0] = 0
for i in range(1, n+1):
    for x in numbers:
        if i-costs[x] >= 0:
            f[i] = max(f[i], f[i-costs[x]]*10+x)
print(f[n])

Verdicts: Wrong Answer

Accepted
Problem: Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:    * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).   * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively.

Submission attempts (in order):
#python3.4
import math
def inpul(): return list(map(int, input().split()))

N, M = inpul()
A = inpul()

c = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010

f[0] = 0
for i in range(1, N+1):
	for x in a:
		if i-c[x] >= 0:
			f[i] = max(f[i], f[i-c[x]]*10+x)
print(f[n])

#python3.4
import math
def inpul(): return list(map(int, input().split()))

N, M = inpul()
A = inpul()

c = [0,2,5,5,4,5,6,3,7,6]
f = [-1]*10010

f[0] = 0
for i in range(1, N+1):
	for x in A:
		if i-c[x] >= 0:
			f[i] = max(f[i], f[i-c[x]]*10+x)
print(f[N])


Verdicts: Runtime Error

Accepted