Problem p03599 (python)

Fixed submission:
# -*- coding:utf-8 -*-

"""解説
https://www.youtube.com/watch?v=nCHz87GMdpo



"""

def solve2():
    """ 全探索O(F**2) """
    A, B, C, D, E, F = list(map(int, input().split()))

    # 水をx, 砂糖をyとする
    sugars = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            y = i*C + j*D
            if y <= F:
                # 作れる砂糖の量y[g]をメモする
                sugars.append(y)

    water = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            x = 100*A*i + 100*B*j
            if x <= F:
                # 作れる水の量x[g]をメモする
                water.append(x)
    
    sugars.sort()
    water.sort()

    # 濃度
    concent = 0
    for x in water:
        for y in sugars:
            if x+y > F:
                break
            if x+y > 0 and y/(x+y) <= E/(100+E):
                if y/(x+y) >= concent:
                    concent = y/(x+y)
                    ans = "{} {}".format(x+y, y)
    print(ans)


def solve():
    """ WA """
    A, B, C, D, E, F = list(map(int, input().split()))

    # dp[i] := 砂糖水i[g]のときに作れる最大の濃度
    # 配るDP
    dp= [0]*(F+1)

    for i in range(0, F+1):
        if i+100*A <= F:
            concent = (dp[i]*i)/(i+100*A)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*A] = max(dp[i+100*A], concent)
        if i+100*B <= F:
            concent = (dp[i]*i)/(i+100*B)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*B] = max(dp[i+100*B], concent)
        if i+C <= F:
            concent = (dp[i]*i+C)/(i+C)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+C] = max(dp[i+C], concent)
        if i+D <= F:
            concent = (dp[i]*i+D)/(i+D)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+D] = max(dp[i+D], concent)
    
    print(dp)
    return
    max_concent = max(dp)
    print(dp.index(max_concent), round(dp.index(max_concent)*max_concent))



if __name__ == "__main__":
    solve2()

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

"""解説
https://www.youtube.com/watch?v=nCHz87GMdpo



"""

def solve2():
    """ 全探索O(F**2) """
    A, B, C, D, E, F = list(map(int, input().split()))

    # 水をx, 砂糖をyとする
    sugars = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            y = i*C + j*D
            if y <= F:
                # 作れる砂糖の量y[g]をメモする
                sugars.append(y)

    water = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            x = 100*A*i + 100*B*j
            if x <= F:
                # 作れる水の量x[g]をメモする
                water.append(x)
    
    sugars.sort()
    water.sort()
    
    # 濃度
    concent = 0
    for x in water:
        for y in sugars:
            if x+y > F:
                break
            if x+y > 0 and y/(x+y) <= E/(100+E):
                if y/(x+y) >= concent:
                    concent = y/(x+y)
                    ans = f"{x+y} {y}"
    print(ans)


def solve():
    """ WA """
    A, B, C, D, E, F = list(map(int, input().split()))

    # dp[i] := 砂糖水i[g]のときに作れる最大の濃度
    # 配るDP
    dp= [0]*(F+1)

    for i in range(0, F+1):
        if i+100*A <= F:
            concent = (dp[i]*i)/(i+100*A)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*A] = max(dp[i+100*A], concent)
        if i+100*B <= F:
            concent = (dp[i]*i)/(i+100*B)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*B] = max(dp[i+100*B], concent)
        if i+C <= F:
            concent = (dp[i]*i+C)/(i+C)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+C] = max(dp[i+C], concent)
        if i+D <= F:
            concent = (dp[i]*i+D)/(i+D)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+D] = max(dp[i+D], concent)
    
    print(dp)
    return
    max_concent = max(dp)
    print(dp.index(max_concent), round(dp.index(max_concent)*max_concent))



if __name__ == "__main__":
    solve2()

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

"""解説
https://www.youtube.com/watch?v=nCHz87GMdpo



"""

def solve2():
    """ 全探索O(F**2) """
    A, B, C, D, E, F = list(map(int, input().split()))

    # 水をx, 砂糖をyとする
    sugars = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            y = i*C + j*D
            if y <= F:
                # 作れる砂糖の量y[g]をメモする
                sugars.append(y)

    water = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            x = 100*A*i + 100*B*j
            if x <= F:
                # 作れる水の量x[g]をメモする
                water.append(x)
    
    # 濃度
    concent = 0
    for x in water:
        for y in sugars:
            if x+y <= F and x+y > 0 and y/(x+y) <= E/(100+E):
                if y/(x+y) >= concent:
                    concent = y/(x+y)
                    ans = f"{x+y} {y}"
    print(ans)


def solve():
    """ WA """
    A, B, C, D, E, F = list(map(int, input().split()))

    # dp[i] := 砂糖水i[g]のときに作れる最大の濃度
    # 配るDP
    dp= [0]*(F+1)

    for i in range(0, F+1):
        if i+100*A <= F:
            concent = (dp[i]*i)/(i+100*A)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*A] = max(dp[i+100*A], concent)
        if i+100*B <= F:
            concent = (dp[i]*i)/(i+100*B)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*B] = max(dp[i+100*B], concent)
        if i+C <= F:
            concent = (dp[i]*i+C)/(i+C)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+C] = max(dp[i+C], concent)
        if i+D <= F:
            concent = (dp[i]*i+D)/(i+D)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+D] = max(dp[i+D], concent)
    
    print(dp)
    return
    max_concent = max(dp)
    print(dp.index(max_concent), round(dp.index(max_concent)*max_concent))



if __name__ == "__main__":
    solve2()