Problem p03290 (python)

Fixed submission:
D,G = map(int,input().split())
PC = []

L = []

t = 10 ** 9
m = 0

for i in range(1,D + 1):
  p,c = map(int,input().split())
  s = 0
  pc = []
  for j in range(p):
    s += i * 100
    if j == p - 1:
      s += c
      L.append([j + 1,s])
    if s >= G and j + 1 < t:
      t = j + 1
    pc.append([j + 1,s])
  PC.append(pc)

def recur(problems):
  #探索の終了
  if len(problems) == D:
    ans = 10 ** 9
    score = 0
    times = 0
    #全部使用した問題セットの合計点と回答数を記録
    for j in range(D):
      if problems[j] == 1:
        score += L[j][1]
        times += L[j][0]
    #全問全回答の例を除く
    if score >= G:
      ans = min(ans,times)
      return ans
    #残りの数以上となる回答数のうち最小のものが見つかれば更新し
    #全回答の回答数に足す
    else:
      remain = G - score
      if remain <= max([L[i][1] for i in range(D) if problems[i] == 0]):
        for k in range(D):
          if problems[k] == 0:
            for l in range(len(PC[k])):
              if remain <= PC[k][l][1] and ans >= PC[k][l][0]:
                ans = PC[k][l][0]
        ans += times
        return ans
      else:
        return 10 ** 9
  
  else:
    #問題セットを全部使う
    ret1 = recur(problems + [1])
    #使わない
    ret2 = recur(problems + [0])
    
    return min(ret1,ret2)

print(recur([]))

Buggy submission (verdict: Runtime Error):
D,G = map(int,input().split())
PC = []

L = []

t = 10 ** 9
m = 0

for i in range(1,D + 1):
  p,c = map(int,input().split())
  s = 0
  pc = []
  for j in range(p):
    s += i * 100
    if j == p - 1:
      s += c
      L.append([j + 1,s])
    if s >= G and j + 1 < t:
      t = j + 1
    pc.append([j + 1,s])
  PC.append(pc)

def recur(problems):
　#探索の終了
  if len(problems) == D:
    ans = 10 ** 9
    score = 0
    times = 0
    #全部使用した問題セットの合計点と回答数を記録
    for j in range(D):
      if problems[j] == 1:
        score += L[j][1]
        times += L[j][0]
    #全問全回答の例を除く
    if score >= G:
      ans = min(ans,times)
      return ans
    #残りの数以上となる回答数のうち最小のものが見つかれば更新し
    #全回答の回答数に足す
    else:
      remain = G - score
      if remain <= max([L[i][1] for i in range(D) if problems[i] == 0]):
        for k in range(D):
          if problems[k] == 0:
            for l in range(len(PC[k])):
              if remain <= PC[k][l][1] and ans >= PC[k][l][0]:
                ans = PC[k][l][0]
        ans += times
        return ans
      else:
        return 10 ** 9
  
  else:
    #問題セットを全部使う
    ret1 = recur(problems + [1])
    #使わない
    ret2 = recur(problems + [0])
    
    return min(ret1,ret2)

print(recur([]))

Buggy submission (verdict: Runtime Error):
D,G = map(int,input().split())
PC = []

L = []

P = [0] * D

t = 10 ** 9
m = 0

for i in range(1,D + 1):
  p,c = map(int,input().split())
  s = 0
  pc = []
  for j in range(p):
    s += i * 100
    if j == p - 1:
      s += c
      L.append([j + 1,s])
    if s >= G and j + 1 < t:
      t = j + 1
    pc.append([j + 1,s])
  PC.append(pc)

def recur(score,times,i,problems):
  if score <= max( [L[i][1] for i in range(D) if P[i] == 0]) and i == 5:
    ans = 10 ** 9
    for j in range(D):
      #使わなかったリストから
      if P[j] == 0:
        #点数のリスト
        for k in range(len(PC[j])):
          #引いた後のスコアを上回る点数のなかから最小値を記録
          if score <= PC[j][k][1] and ans >= PC[j][k][1]:
            ans = PC[j][k][0]
    ans += times
    return ans
  
  elif i == 5:
    return 10 ** 9
  
  else:
    #使う
    ret1 = recur(score - L[i][1],times + L[i][0],i + 1,P[i] + 1)
    #使わない
    ret2 =recur(score,times,i + 1,P[i] + 0)
    
    return min(ret1,ret2)

if t == 10 ** 9:
  print(recur(G,0,0,P))
  
else:
  print(t)