Problem p03599 (python)

Fixed submission:
import sys
A, B, C, D, E, F = map(int, input().split())


def concentration(water, suger):
    if water * E/100 < suger or water + suger == 0:
        return 0
    return (100 * suger/(water + suger))

lst_w = []
limit_w = (F+A*100-1)//(A*100)
for i in range(limit_w):
    for j in range(limit_w):
        if 100 * (A * i + B * j) <= F:
            lst_w += [100 * (A * i + B * j)]

lst_s = []
limit_s = (F+C-1)//C
for i in range(limit_s):
    for j in range(limit_s):
        if C* i + D * j <= F:
            lst_s += [C * i + D * j]

# print (lst_w)
# print (lst_s)
set_w = set(lst_w)
set_s = set(lst_s)

# print (set_w)
# print (set_s)

ans = 0
ans_total = 0
ans_suger = 0
for water in set_w:
    for suger in set_s:
        if water + suger <= F:
            a = concentration(water, suger)
            if ans < a:
                ans = a
                ans_total = water + suger
                ans_suger = suger
            if ans == 50:
                print (ans_total, ans_suger)
                sys.exit()

if ans == 0:
    print (A * 100, 0)
else:
    print (ans_total, ans_suger)

# print (ans)

Buggy submission (verdict: Runtime Error):
import sys
A, B, C, D, E, F = map(int, input().split())


def concentration(water, suger):
    if water * E/100 < suger or water + suger == 0:
        return 0
    return (100 * suger/(water + suger))

lst_w = []
limit_w = (F+A*100-1)//(A*100)
for i in range(limit_w):
    for j in range(limit_w):
        if 100 * (A * i + B * j) <= F:
            lst_w += [100 * (A * i + B * j)]

lst_s = []
limit_s = (F+C-1)//C
for i in range(limit_s):
    for j in range(limit_s):
        if C* i + D * j <= F:
            lst_s += [C * i + D * j]

# print (lst_w)
# print (lst_s)
set_w = set(lst_w)
set_s = set(lst_s)

# print (set_w)
# print (set_s)

ans = 0
ans_total = 0
ans_suger = 0
for water in set_w:
    for suger in set_s:
        if water + suger <= F:
            a = concentration(water, suger)
            if ans < a:
                ans = a
                ans_total = water + suger
                ans_suger = suger
            if ans == 50:
                print (ans_total, ans_suger)
                sys.exit()

if ans = 0:
    print (A * 100, 0)
else:
    print (ans_total, ans_suger)

# print (ans)

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())


def concentration(water, suger):
    if water * E/100 < suger or water + suger == 0:
        return 0
    return (100 * suger/(water + suger))

lst_w = []
limit_w = (F+A*100-1)//(A*100)
for i in range(limit_w):
    for j in range(limit_w):
        if 100 * (A * i + B * j) <= F:
            lst_w += [100 * (A * i + B * j)]

lst_s = []
limit_s = (F+C-1)//C
for i in range(limit_s):
    for j in range(limit_s):
        if C* i + D * j <= F:
            lst_s += [C * i + D * j]

# print (lst_w)
# print (lst_s)
set_w = set(lst_w)
set_s = set(lst_s)

# print (set_w)
# print (set_s)

ans = 0
for water in set_w:
    for suger in set_s:
        if water + suger <= F:
            a = concentration(water, suger)
            if ans < a:
                ans = a
                ans_total = water + suger
                ans_suger = suger

# print (ans)
print (ans_total, ans_suger)