Problem p03599 (python)

Fixed submission:
from operator import itemgetter

A, B, C, D, E, F = list(map(int,input().split()))
X = []
ans = 1000
for i in range(31):
    for j in range(31):
        for k in range(51):
            for l in range(51):
                if 100*A*i+100*B*j+C*k+D*l != 0:
                    if 100*A*i+100*B*j+C*k+D*l <= F and (C*k+D*l)/(100*A*i+100*B*j+C*k+D*l) <= E/(100 + E):
                        ans =(E/(100 + E) - (C*k+D*l)/(100*A*i+100*B*j+C*k+D*l))
                        X.append([ans , 100*A*i+100*B*j+C*k+D*l, C*k+D*l])
X = sorted(X,key=itemgetter(0),reverse = False) 

print(X[0][1],X[0][2])

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

A, B, C, D, E, F = list(map(int,input().split()))
X = []

for a in range(31):
    for b in range(31):
        for c in range(71)       #範囲の指定がよくわからない
            for d in range(71):  #範囲の指定がよくわからない
                w = 100*A*a+100*B*b #水の質量
                s = C*c+D*d        #砂糖の質量
                if w == 0  or w + s >= F: #ダメな条件 砂糖０はあり得る
                    break
                else:
                    if s/(w+s) <= E/(100 + E):
                        ans = 100 * s/(w+s)
                        X.append([ans,w + s, s])
X = sorted(X,key=itemgetter(0),reverse = True) 
#print(X)
print(X[0][1],X[0][2])

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

A, B, C, D, E, F = list(map(int,input().split()))
X = []

for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = 100*A*a+100*B*b #砂糖水の質量
                s = C*c+D*d        #砂糖の質量
                if w == 0 or s == 0 or w + s >= F: #ダメな条件
                    break
                else:
                    if s/(w+s) <= E/(100 + E):
                        ans = 100 * s/(w+s)
                        X.append([ans,w + s, s])
X = sorted(X,key=itemgetter(0),reverse = True) 
print(X[0][1],X[0][2])

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

A, B, C, D, E, F = list(map(int,input().split()))
X = []
ans = 1000
for a in range(31):
    for b in range(31):
        for c in range(31):
            for d in range(31):
                w = 100*A*a+100*B*b #砂糖水の質量
                s = C*c+D*d        #砂糖の質量
                if w == 0 or s == 0 or w + s >= F: #ダメな条件
                    break
                else:
                    if s/(w+s) <= E/(100 + E):
                        ans = 100 * s/(w+s)
                        X.append([ans,w + s, s])
X = sorted(X,key=itemgetter(0),reverse = True) 
print(X[0][1],X[0][2])

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

A, B, C, D, E, F = list(map(int,input().split()))
X = []
ans = 1000
for a in range(31):
    for b in range(31):
        for c in range(31):
            for d in range(31):
                w = 100*A*a+100*B*b #砂糖水の質量
                s = C*c+D*d        #砂糖の質量
                if w == 0:
                    break
                if s == 0 :
                    break
                if w + s > F:
                    break
                else:
                    if w/100 * E >= s:
                        ans = 100 * s/(w+s)
                        X.append([ans,w + s, s])
X = sorted(X,key=itemgetter(0),reverse = True) 
print(X[0][1],X[0][2])