Problem p02618 (python)

Fixed submission:
import sys
readline = sys.stdin.readline

D = int(readline())
C = list(map(int,readline().split()))
for i in range(D):
  S = list(map(int,readline().split()))
  
for i in range(D):
  print(1)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

# 0-indexでやる

D = int(readline())
C = list(map(int,readline().split())) # 満足度の下がりやすさ
S = [None] * D
sortS = [None] * D
for i in range(D):
  s = list(map(int,readline().split()))
  S[i] = s.copy()
  for j in range(len(s)):
    s[j] = (s[j],j)
  sortS[i] = sorted(s, key = lambda x:x[0], reverse = True)

def make_ans(D,C,limiter = 52, threshold = 26, balance = 0.5):
  ans = []
  last_submit = [-26] * 26
  for i in range(D):
    info = sortS[i]
    
    # limiter回以上提出がないものがあれば、threshold回を超えたもののうちCの値が高いものを提出
    if i - min(last_submit) >= limiter:
      ind = -1
      for j in range(len(last_submit)):
        if i - last_submit[j] >= threshold:
          if ind == -1:
            ind = j
          else:
            if C[ind] < C[j]:
              ind = j
      ans += [ind]
      last_submit[ind] = i
      continue
      
    topval = info[0][0]
    for j in range(len(info)):
      val = info[j][0]
      if val < topval * (balance):
        continue # 最高値の半分になるのであればやめよう
      index = info[j][1]
      if i - last_submit[index] < 26:
        continue
      ans += [index]
      last_submit[index] = i
      break
    else:
      ans += [info[0][1]]
  return ans

def calc_score(arr):
  point = 0
  last_submit = [0] * 26
  for i in range(len(arr)):
    # i日目
    point += S[i][arr[i]]
    for j in range(len(last_submit)):
      point -= (i - last_submit[j]) * C[i]
  return point
      
ans = make_ans(D,C)
best = calc_score(ans)
for limiter in range(30,60):
  for threshold in range(26, limiter):
    for balance in (0.2, 0.25, 0.42, 0.5, 0.63, 0.75, 0.8):
      new_ans = make_ans(D,C,limiter,threshold,balance)
      new_score = calc_score(new_ans)
      if new_score > best:
        ans = new_ans
        best = new_score
  
def show(arr):
  for a in arr:
    print(a + 1)
    
show(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

# 0-indexでやる

D = int(readline())
C = list(map(int,readline().split())) # 満足度の下がりやすさ
S = [None] * D
sortS = [None] * D
for i in range(D):
  s = list(map(int,readline().split()))
  S[i] = s.copy()
  for j in range(len(s)):
    s[j] = (s[j],j)
  sortS[i] = sorted(s, key = lambda x:x[0], reverse = True)

def make_ans(D,C,limiter = 52, threshold = 26):
  ans = []
  last_submit = [-26] * 26
  for i in range(D):
    info = sortS[i]
    
    # 52回以上提出がないものがあれば、42回を超えたもののうちCの値が高いものを提出
    if i - min(last_submit) >= limiter:
      ind = -1
      for j in range(len(last_submit)):
        if i - last_submit[j] >= threshold:
          if ind == -1:
            ind = j
          else:
            if C[ind] < C[j]:
              ind = j
      ans += [ind]
      last_submit[ind] = i
      continue
      
    topval = info[0][0]
    for j in range(len(info)):
      val = info[j][0]
      if val < topval // 2:
        continue # 最高値の半分になるのであればやめよう
      index = info[j][1]
      if i - last_submit[index] < 26:
        continue
      ans += [index]
      last_submit[index] = i
      break
    else:
      ans += [info[0][1]]
  return ans

def calc_score(arr):
  point = 0
  last_submit = [0] * 26
  for i in range(len(arr)):
    # i日目
    point += S[i][arr[i]]
    for j in range(len(last_submit)):
      point -= (i - last_submit[j]) * C[i]
  return point
      
ans = make_ans(D,C)

best = calc_score(ans)
for limiter in range(30,53):
  for threshold in range(26, limiter):
    new_ans = make_ans(D,C,limiter,threshold)
    new_score = calc_score(new_ans)
    if new_score > best:
      print("yes",new_score,best)
      ans = new_ans
      best = new_score
  
def show(arr):
  for a in arr:
    print(a + 1)
    
show(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

# 0-indexでやる

D = int(readline())

C = list(map(int,readline().split())) # 満足度の下がりやすさ

last_submit = [-26] * 26

for i in range(D):
  S = list(map(int,readline().split()))
  
  # 52回以上提出がないものを見つけたら、それを強制提出
  fin = False
  for j in range(len(last_submit)):
    if i - last_submit[j] >= 52:
      print(S[j][1] + 1)
      last_submit[j] = i
      fin = True
      break
  if fin:
    continue
  for j in range(len(S)):
    S[j] = (S[j],j)
  S = sorted(S, key = lambda x:x[0], reverse = True)
  topval = S[0][0]
  for j in range(len(S)):
    val = S[j][0]
    if val < topval // 2:
      continue # 最高値の半分になるのであればやめよう
    index = S[j][1]
    if i - last_submit[index] < 26:
      continue
    print(index + 1)
    last_submit[index] = i
    break
  else:
    print(S[0][1] + 1)