Problem p03599 (python)

Fixed submission:
a, b, c, d, e, f = map(int, input().split())

water = [False]*(f+1)
suger = [False]*(f+1)

for i in range(0, f+1, a*100):
  water[i] = True
for i in range(f+1):
  if (i == 0 or water[i]) and i+b*100 <= f:
    water[i+b*100] = True
  
for i in range(0, f+1, c):
  suger[i] = True
for i in range(f+1):
  if (i == 0 or suger[i]) and i+d <= f:
    suger[i+d] = True

ans_w, ans_s = a*100, 0
for i in range(f+1):
  if water[i] == False:
    continue
  for j in range(f, -1, -1):
    if suger[j] == False or j*(100+e) > (j+i)*e or j+i > f:
      continue
    if j*(ans_w+ans_s) > (j+i)*ans_s:
      ans_w, ans_s = i, j
    break
print(ans_w+ans_s, ans_s)

Buggy submission (verdict: Runtime Error):
import sys
a, b, c, d, e, f = map(int, input().split())

water = set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        k = 100*(i*a+j*b)
        if k == 0:
            continue
        if k <= f:
            water.add(k)
            continue
        break

water = list(water)
water.sort()

if not water:
    print(0, 0)
    sys.exit()
suger = set()
for i in range(water[-1]*e//(100*c)+1):
    for j in range(water[-1]*e//(100*d)+1):
        k = i*c+j*d
        if k <= f:
            suger.add(k)
        else:
            break

suger = list(suger)
suger.sort()


weight_water, weight_suger = 0, 0
ratio = 0
n = len(suger)
for w in water:
    if w == 0:
        continue
    bit_l, bit_r = 0, n
    while bit_r - bit_l > 1:
        key = (bit_r+bit_l)//2
        s = suger[key]
        if s+w <= f and s*100 <= e*w:
            bit_l = key
        else:
            bit_r = key
    if bit_l == n-1 and (suger[bit_l]/(suger[bit_l]+w) > e or suger[bit_l]+w > f):
        continue
    if bit_l == 0 and suger[1]/(suger[1]+w) <= e and suger[1]+w <= f:
        ws = suger[1]
    else:
        ws = suger[bit_l]
    if ratio*w < ws*100 <= e*w:
        ratio = ws*100/w
        weight_water, weight_suger = w+ws, ws
print(weight_water, weight_suger)

Buggy submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())

water = set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        k = 100*(i*a+j*b)
        if k == 0:
            continue
        if k <= f:
            water.add(k)
        else:
            break

water = list(water)
water.sort()

suger = set()
for i in range(water[-1]*e//(100*c)+1):
    for j in range(water[-1]*e//(100*d)+1):
        k = i*c+j*d
        if k <= f:
            suger.add(k)
        else:
            break

suger = list(suger)
suger.sort()


weight_water, weight_suger = 0, 0
ratio = 0
n = len(suger)
for w in water:
    if w == 0:
        continue
    bit_l, bit_r = 0, n
    while bit_r - bit_l > 1:
        key = (bit_r+bit_l)//2
        s = suger[key]
        if s+w <= f and s*100 <= e*w:
            bit_l = key
        else:
            bit_r = key
    if bit_l == n-1 and (suger[bit_l]/(suger[bit_l]+w) > e or suger[bit_l]+w > f):
        continue
    if bit_l == 0 and suger[1]/(suger[1]+w) <= e and suger[1]+w <= f:
        ws = suger[1]
    else:
        ws = suger[bit_l]
    if ratio*w < ws*100 <= e*w:
        ratio = ws*100/w
        weight_water, weight_suger = w+ws, ws
print(weight_water, weight_suger)

Buggy submission (verdict: Runtime Error):
import sys

a, b, c, d, e, f = map(int, input().split())

water = set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        k = 100*(i*a+j*b)
        if k == 0:
            continue
        if k <= f:
            water.add(k)
        else:
            break

water = list(water)
water.sort()

suger = set()
for i in range(water[-1]*e//(100*c)+1):
    for j in range(water[-1]*e//(100*d)+1):
        k = i*c+j*d
        if k <= f:
            suger.add(k)
        else:
            break

suger = list(set(suger))
suger.sort()


weight_water, weight_suger = 0, 0
ratio = 0
n = len(suger)
for w in water:
    bit_l, bit_r = 0, n
    while bit_r - bit_l > 1:
        key = (bit_r+bit_l)//2
        s = suger[key]
        if s+w <= f and s*100 <= e*w:
            bit_l = key
        else:
            bit_r = key
    if bit_l == n-1 and (suger[bit_l]/(suger[bit_l]+w) > e or suger[bit_l]+w > f):
        continue
    if bit_l == 0 and suger[1]/(suger[1]+w) <= e and suger[1]+w <= f:
        ws = suger[1]
    else:
        ws = suger[bit_l]
    if ratio*w < ws*100 <= e*w:
        ratio = ws*100/w
        weight_water, weight_suger = w+ws, ws
print(weight_water, weight_suger)