Problem p03599 (python)

Fixed submission:
#083c
import sys

A,B,C,D,E,F = map(int, input().split())
#水*100、水*100、砂糖、砂糖

#合計はF以下、溶け残りはダメ
#水100に対してE溶ける → 100E/(100+E) が最大値

#砂糖水の濃度は 100b/(a+b)
#水a,砂糖b

max_conc = 0
total_weight_at_max_conc = 100*A
sugar_weight_at_max_conc = 0

for h in range(0, 1+int(F/(100*A))): #F<=3000,1<=Aより 最大30回ループ
    limit_water = F - (h*100*A)
    
    for i in range(0, 1+int(limit_water/(100*B))):
        limit_total_sugar_by_weight = F - (h*100*A + i*100*B)
        limit_total_sugar_by_conc = (h*100*A + i*100*B)/100*E
        limit_total_sugar = min(limit_total_sugar_by_weight,limit_total_sugar_by_conc)
            
        for j in range(0, 1+int(limit_total_sugar/C)):
            limit_D_sugar_by_weight = F - (h*100*A + i*100*B + j*C)
            limit_D_sugar_by_conc = (h*100*A + i*100*B)/100*E - j*C
            limit_D_sugar = min(limit_D_sugar_by_weight,limit_D_sugar_by_conc) 
            
            k = int(limit_D_sugar/D) #濃度を濃くするために操作Dは限界まで行う。
            
            if h>=0 and i>=0 and j>=0 and k>=0:
                a = h*100*A + i*100*B
                b = j*C + k*D
                total_weight = a + b
                
                #print(h,i,j,k)
                #print(a,b)
                
                if a + b != 0:
                    concentration = 100*b/(a+b)

                    if concentration > max_conc:
                        max_conc = concentration
                        total_weight_at_max_conc = total_weight
                        sugar_weight_at_max_conc = b

                        if max_conc == 100*E/(100+E):
                            print(total_weight_at_max_conc,sugar_weight_at_max_conc)
                            sys.exit()

print(total_weight_at_max_conc,sugar_weight_at_max_conc)

Buggy submission (verdict: Runtime Error):
#074c
A,B,C,D,E,F = map(int, input().split())
    
#あり得る水量をすべて書き出す
set_water = set()

for i in range(F//(100*A),-1,-1):
    for j in range((F-(100*A*i))//(100*B),-1,-1):
        water = 100*A*i + 100*B*j
        if water not in set_water:
            set_water.add(water)

#print(set_water)

set_water_and_sugar = set()

#def get_conc(water,sugar,E,F):
#    if water/100*E < sugar or water+sugar == 0: #water + sugar > F or  …すでに制約済み
#        return 0
#    else:
#        return (100*sugar)/(water+sugar)

#あり得る水量に対して、ありえる砂糖の量をすべて書き出す (溶け残りの制約があるのでMAXのみではNG)
#for water in set_water:
#    for i in range((F-water)//C,-1,-1):
#        for j in range((F-water-C*i)//D,-1,-1):
#            sugar = C*i + D*j
#            if tuple([water,sugar]) not in set_water_and_sugar:
#                set_water_and_sugar.add(tuple([water,sugar]))              

#あり得る水量に対して、砂糖を限界量(重量制限or溶け残り制限)まで入れる
for water in set_water:
    for i in range((F-water)//C,-1,-1):
        j = min((water/100*E - C*i)//D , (F - water - C*i)//D)
        sugar = C*i + D*j
        if tuple([water,sugar]) not in set_water_and_sugar and sugar >= 0:
            #print(water,sugar,water+sugar,water/100*E)
            set_water_and_sugar.add(tuple([water,sugar]))
            
#最大濃度を求める
limit_conc = (100*E)/(100+E)
max_conc = 0
max_water_and_sugar = [0,0]

for water_and_sugar in set_water_and_sugar:
    water = water_and_sugar[0]
    sugar = water_and_sugar[1]
    conc = get_conc(water,sugar,E,F)
    
    #print(water,sugar,conc)
    
    if max_conc < conc:
        max_conc = conc
        max_water_and_sugar = [water,sugar]
        
        #最高濃度に達したら抜ける
        if max_conc == limit_conc:
            break
        
print(int(sum(max_water_and_sugar)),int(max_water_and_sugar[1]))