Problem p03290 (python)

Fixed submission:
# encoding: utf-8
D_MAX = 10
P_MAX = 100

num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]
D, G = num_and_pnt(input().split())
# [pi, ci]
pc = [num_and_pnt(input().split()) for i in range(D)]

G_list = [(i + 1) * x[0] + x[1] for i, x in enumerate(pc)]
cnt_list = [x[0] for i, x in enumerate(pc)]
idx = [map(int, format(i, "b")) for i in range(2 ** D)]

# i, G_comp, cnt_comp
table = [ (i, sum([((i // (2 ** j)) % 2) * G_list[j] for j in range(D)]), sum([((i // (2 ** j)) % 2) * cnt_list[j] for j in range(D)])) for i in range(2 ** D)] # very long
# print(table)
mincnt = D_MAX * P_MAX
for i, (G_last, cnt_last) in enumerate(zip(G_list, cnt_list)):
    for j, G_comp, cnt_comp in filter(lambda x: (((x[0] // (2 ** i)) % 2 == 0) and (x[1] <= G < x[1] + G_last) and (x[2] < mincnt)), table):
        # print(i, (G_last, cnt_last), j, G_comp, cnt_comp)
        cnt_last_tmp = min((-((G_comp - G) // (i + 1)), cnt_last))
        if cnt_comp + cnt_last_tmp < mincnt: mincnt = cnt_comp + cnt_last_tmp

print(mincnt)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8

P_MAX = 100

num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]

def mycounter(item, G):
    Gtmp = (item[1] + 1) * item[2] + item[3]
    p_th = item[2]
    for i in range(item[2]):
        if Gtmp < G: break
        else:
            p_th -= 1
            Gtmp = (item[1] + 1) * p_th
    return p_th + 1

D, G = num_and_pnt(input().split())

# [flag, index, pi, ci]
pc = [[1, i] + num_and_pnt(input().split()) for i in range(D)]

cnt = 0
while True:
    # last point

    state = -1
    p_tmp = P_MAX
    for item in filter(lambda x: x[0] > 0, pc):
        Gtmp = (item[1] + 1) * item[2] + item[3]
        if G <= Gtmp:
            p = mycounter(item, G)
            if p < p_tmp:
                state = item[1]
                p_tmp = p
    # escape
    if state > -1:
        cnt += p_tmp
        # print("#", (state + 1) * 100, p_tmp)
        break
    # completed point
    item = max(list(filter(lambda x: x[0] > 0, pc)), key=lambda x: x[1] + x[3] / x[2])
    G -= (item[1] + 1) * item[2] + item[3]
    cnt += item[2]
    pc[item[1]][0] = 0
    # print("#", (item[1] + 1) * 100, item[2], G)
    
print(cnt)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8

P_MAX = 100

num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]

def mycounter(item, G):
    Gtmp = (item[1] + 1) * item[2] + item[3]
    p_th = item[2]
    for i in range(item[2]):
        if Gtmp < G: break
        else:
            p_th -= 1
            Gtmp = (item[1] + 1) * p_th
    return p_th + 1

D, G = num_and_pnt(input().split())

# [flag, index, pi, ci]
pc = [[1, i] + num_and_pnt(input().split()) for i in range(D)]

cnt = 0
while True:
    # last point
    # print(G * 100, cnt, pc)
    state = -1
    p_tmp = P_MAX
    for item in filter(lambda x: x[0] > 0, pc):
        Gtmp = (item[1] + 1) * item[2] + item[3]
        if G <= Gtmp:
            p = mycounter(item, G)
            if p < p_tmp:
                # print(G * 100, (item[1] + 1) * 100, p)
                state = item[1]
                p_tmp = p
    # escape
    if state > -1:
        cnt += p_tmp
        break
    # completed point
    # print(pc)
    item = max(flist(ilter(lambda x: x[0] > 0, pc), key=lambda x: x[1] + x[3] / x[2]))
    G -= (item[1] + 1) * item[2] + item[3]
    cnt += item[2]
    pc[item[1]][0] = 0
    
print(cnt)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8

P_MAX = 100

num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]

def mycounter(item, G):
    Gtmp = (item[1] + 1) * item[2] + item[3]
    p_th = item[2]
    for i in range(item[2]):
        if Gtmp < G: break
        else:
            p_th -= 1
            Gtmp = (item[1] + 1) * p_th
    return p_th + 1

D, G = num_and_pnt(input().split())

# [flag, index, pi, ci]
pc = [[1, i] + num_and_pnt(input().split()) for i in range(D)]

cnt = 0
while True:
    # last point
    # print(G * 100, cnt, pc)
    state = -1
    p_tmp = P_MAX
    for item in filter(lambda x: x[0] > 0, pc):
        Gtmp = (item[1] + 1) * item[2] + item[3]
        if G <= Gtmp:
            p = mycounter(item, G)
            if p < p_tmp:
                # print(G * 100, (item[1] + 1) * 100, p)
                state = item[1]
                p_tmp = p
    # escape
    if state > -1:
        cnt += p_tmp
        break
    # completed point
    # print(pc)
    item = max(filter(lambda x: x[0] > 0, pc), key=lambda x: x[1] + x[3] / x[2])
    G -= (item[1] + 1) * item[2] + item[3]
    cnt += item[2]
    pc[item[1]][0] = 0
    
print(cnt)

Buggy submission (verdict: Runtime Error):
# encoding: utf-8

P_MAX = 100

num_and_pnt = lambda x: [int(x[0]), int(x[1]) // 100]

def mycounter(item, G):
    Gtmp = (item[1] + 1) * (item[2] - 1)
    p = item[2]
    for i in range(p):
        if Gtmp < G: break
        else:
            Gtmp -= (item[1] + 1)
            p -= 1
    return p

D, G = num_and_pnt(input().split())

# [flag, index, pi, ci]
pc = [[1, i] + num_and_pnt(input().split()) for i in range(D)]

cnt = 0
while True:
    # print(pc)
    # last point
    state = -1
    p_tmp = P_MAX
    for item in filter(lambda x: x[0] > 0, pc):
        Gtmp = (item[1] + 1) * item[2] + item[3]
        if G <= Gtmp:
            p = mycounter(item, G)
            if p < p_tmp:
                state = item[1]
                p_tmp = p
    # escape
    if state > -1:
        cnt += p_tmp
        break
    # completed point
    item = max(filter(lambda x: x[0] > 0, pc), key=lambda x: x[1] + x[3] / x[2])
    G -= (item[1] + 1) * item[2] + item[3]
    cnt += item[2]
    pc[item[1]][0] = 0
    
print(cnt)