Problem: We have N locked treasure boxes, numbered 1 to N.  A shop sells M keys. The i-th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1}, c_{i2}, ..., c_{i{b_i}}. Each key purchased can be used any number of times.  Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1.

Submission attempts (in order):
n,m = map(int, input().split())

dp = [[float("inf") for _ in range(2**n)] for _ in range(m)]
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
    for j in range(2**n):
        jord = j | d
        
        #initialize
        if i==0:
            dp[0][d] = a
        else:
            dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a)
            
if dp[m-1][2**n-1] == float("inf"):
    print(-1)
else:
    print(int(dp[m-1][2**n-1]))

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

inf = 10**9

dp = [[inf for _ in range(2**n)]] * m
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    #initialize
    if i==0:
        dp[0][d] = a
        continue
        
    for j in range(2**n):
        jord = j | d
        print(jord)
        dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a)
        print(dp[i][jord])
            
if dp[m-1][2**n-1] == inf:
    print(-1)
else:
    print(dp[m-1][2**n-1])

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

dp = [[float("inf") for _ in range(2**n)] for _ in range(m)]
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
    for j in range(2**n):
        jord = j | d
        
        #initialize
        if i==0:
            dp[0][d] = a
        else:
            dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a)
            
if dp[m-1][2**n-1] == float("inf"):
    print(-1)
else:
    print(dp[m-1][2**n-1])

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

dp = [[float("inf") for _ in range(2**n)] for _ in range(m)]
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    #initialize
    if i==0:
        dp[0][d] = a
        continue
        
    for j in range(2**n):
        jord = j | d
        dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a)
            
if dp[m-1][2**n-1] == float("inf"):
    print(-1)
else:
    print(int(dp[m-1][2**n-1]))

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

dp = [[int("inf") for _ in range(2**n)] for _ in range(m)]
dp[0][0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
    for j in range(2**n):
        jord = j | d
        
        #initialize
        if i==0:
            dp[0][d] = a
        else:
            dp[i][jord] = min(dp[i-1][jord], dp[i-1][j] + a)
            
if dp[m-1][2**n-1] == int("inf"):
    print(-1)
else:
    print(dp[m-1][2**n-1])


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

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[i][jord] = min(dp[i][jord], dp[i][j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])


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

inf = 10**9

dp =[inf for _ in range(2**n)]
dp[0] = 0

for i in range(m):
    a,b = map(int, input().split())
    d = sum((1<<(i-1)) for i in map(int, input().split()))
  
    for j in range(2**n):
        jord = j | d
        dp[jord] = min(dp[jord], dp[j] + a)
            
if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted