Problem:


Score : 300 points

Problem Statement

Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.

Operation 1: Pour 100A grams of water into the beaker.

Operation 2: Pour 100B grams of water into the beaker.

Operation 3: Put C grams of sugar into the beaker.

Operation 4: Put D grams of sugar into the beaker.

In our experimental environment, E grams of sugar can dissolve into 100 grams of water.

Snuke will make sugar water with the highest possible density.

The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.

We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

Constraints

1 \leq A < B \leq 30

1 \leq C < D \leq 30

1 \leq E \leq 100

100A \leq F \leq 3 000

A, B, C, D, E and F are all integers.

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10

In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.

We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:

If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.

If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934



Sample input:
1 2 10 20 15 200


Sample output:
110 10

Submission status: Accepted

Solution code:
def main():
    A, B, C, D, E, F = map(int, input().split())

    W = [100*A*x + 100*B*y for x in range(0, 31) for y in range(0, 31) if 0 < (100*A*x + 100*B*y) <= F]
    S = [C*x + D*y for x in range(0, 3001) for y in range(0, 3001) if 0 < (C*x + D*y) <= F]

    dense, sugar, mass = 0, 0, 100*A
    for w in W:
        for s in S:
            if ((w+s) <= F and s <= (w*E/100) and dense*(s+w) < s):
                dense = s/(s+w)
                sugar = s
                mass = s+w
    print(mass, sugar)

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B,C,D,E,F = list(map(int, input().split()))

W = [ 100*A*x + 100*B*y for x in range(0,31) for y in range(0,31) if 0 < (100*A*x + 100*B*y) <= F]
S = [ C*x + D*y for x in range(0,3001) for y in range(0,3001) if 0 < (C*x + D*y) <= F]

dense = 0
sugar = 0
mass = 100*A
for w in W:
    for s in S:
        if ((w + s) <= F and s <= (w*E/100) and dense*(s+w) < s):
            dense = s/(s+w)
            sugar = s
            mass = s+w
print(mass,sugar)

Submission status: Accepted

Solution code:
from itertools import product


def main():
    """
    1 ≦ A < B ≦ 30
    1 ≦ C < D ≦ 30
    1 ≦ E ≦ 100
    100A ≦ F ≦ 3000 より
       A,B: 30回まで
       C,D: 100回まで
    """
    A, B, C, D, E, F = map(int, input().split())

    ans_w = 0
    ans_s = 0
    for a, b, c in product(range(31),
                           range(31),
                           range(101)):
        for d in range(101):
            w = (100 * A * a) + (100 * B * b)
            s = C * c + D * d

            if w == 0 or (w + s) > F:
                break

            # Sugar: Water = E: 100
            if s * 100 == w * E:
                print(w + s, s)
                return

            # Sugar: Water > E: 100 なら溶け切らない
            # s/w > E/100
            if s * 100 > E * w:
                break

            # 以前の最大濃度との比較(基準の100, Eを置き換え)
            # s: w > a_w: a_s
            if (ans_w, ans_s) == (0, 0) or \
                    s * ans_w > ans_s * w:
                ans_w, ans_s = w, s

    print(ans_w + ans_s, ans_s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def Sugar_water():
    key_list = ["wA", "wB", "sC", "sD", "dE", "tF"]
    # val = "1 2 1 2 100 1000"
    val = "17 19 22 26 55 2802"
    # val = "1 2 1 2 1 101"
    if 'LOCAL_FLAG' in globals():
        val_list = list(map(int, val.split()))
    else:
        val_list = list(map(int, input().split()))

    var = dict(zip(key_list, val_list))
    limit = var.copy()

    m_density=0
    m_sugar=0
    m_water=0

    limit_density=var['dE']/(100+var['dE'])
    limit['wA'] = int(var['tF']/100/var['wA'])
    limit['wB'] = int(var['tF']/100/var['wB'])

    for A in range(0, limit['wA']+1):
        for B in range(0, limit['wB']+1):
            water = 100*var['wA']*A + 100*var['wB']*B
            if(water > var['tF']):
                break
            elif((var['tF']-water)*m_density > (var['tF']-water)):
                break
            limit['sC'] = int(water/100*var['dE']/var['sC'])
            limit['sD'] = int(water/100*var['dE']/var['sD'])

            for C in range(0, limit['sC']+1):
                for D in range(0, limit['sD']+1):
                    sugar = var['sC']*C + var['sD']*D

                    total = water + sugar
                    density = sugar / total if total > 0 else 0

                    if(total > var['tF']):
                        break
                    elif(density > limit_density):
                        break
                    elif(density > m_density):
                        # print("# ", total, " ", sugar, " ", density, "  -- ", A, B, C, D)
                        m_density=density
                        m_sugar=sugar
                        m_water=water


    if(m_water == 0):
        m_water = 100*var['wA']
    print(m_sugar + m_water, " ", m_sugar)

Sugar_water()

Submission status: Accepted

Solution code:
#coding:utf-8
import math

A, B, C, D, E, F = map(int, input().split(" "))

w_list = []
for i in range(math.ceil(F / (100 * A)) + 1):
    for j in range(math.ceil(F / (100 * B)) + 1):
        if i == 0 and j == 0:
            continue
        water = 100 * A * i + 100 * B * j
        if water <= F:
            w_list.append(water)

s_list = []
for i in range(math.ceil(F / C) + 1):
    for j in range(math.ceil(F / D) + 1):
        sugar = C * i + D * j
        if sugar <= F:
            s_list.append(sugar)

max_c = 0
max_w = 100 * A
max_s = 0
for w in set(w_list):
    for s in set(s_list):
        if w + s > F:
            continue
        if s > int(E * w / 100):
            continue
        c = 100 * s / (w + s)
        if c > max_c:
            max_c = c
            max_w = w
            max_s = s

print(max_w + max_s, max_s, end = " ")

Submission status: Accepted

Solution code:
def node(hen, sin):
    if hen == 0 or sin == 0:
        return 0
    return 100 * sin / (hen + sin)


a, b, c, d, e, f = [int(i) for i in input().split()]
node_ans = 0
water_ans = 0
sugar_ans = 0
for A in range(0, f, a * 100):
    for B in range(0, f, b * 100):
        water = A + B
        max_sugar = water * e
        for C in range(0, f, c):
            for D in range(0, f, d):
                sugar = C + D
                if max_sugar < sugar*100 or f < water + sugar or water == 0:
                    break
                elif node_ans <= node(water, sugar):
                    node_ans = node(water, sugar)
                    sugar_ans = sugar
                    water_ans = water

print(water_ans + sugar_ans, sugar_ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
A , B , C , D , E , F = map(int ,input().split())
def solve():
    ans = (100*A , 0)
    for a in range(0,F,100*A):
        for b in range(0,F,100*B):
            water = a + b
            for c in range(0,F,C):
                for d in range(0,F,D):
                    sugar = c + d
                    if water + sugar > F or 100*sugar > E*water or water ==0:
                        break
                    elif 100*sugar == E*water:
                        return (water,sugar)
                    elif sugar*ans[0] > ans[1]*water:
                        ans = (water , sugar)
    return ans
ans = solve()
print(sum(ans),ans[1])

Submission status: Accepted

Solution code:
def nodef(w,s):
    return (s/(s+w))


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

best_w = 0
best_s = 0
best_node = 0

for i in range(30//a+1):
    for j in range(30//b+1):
        w = 100*(a*i + b*j)
        if w<=f and w:
            max_s = min(f-w,(a*i + b*j)*e)
            for k in range(max_s//c+1):
                l = (max_s-k*c)//d
                s = k*c + l*d
                node = nodef(w,s)
                if node >= best_node and node<=e and w+s<=f:
                    best_w = w
                    best_s = s
                    best_node = node
                    
print("{} {}".format((best_s+best_w ),best_s))

Submission status: Accepted

Solution code:
def main():
    global E, F
    A, B, C, D, E, F = map(int, input().split())

    waterA, waterB = 100 * A, 100 * B
    water = set()
    i = 0
    while waterA * i <= F:
        j = 0
        while waterA * i + waterB * j <= F:
            water.add(waterA * i + waterB * j)
            j += 1
        i += 1

    sugar = set()
    i = 0
    while C * i <= F // 100 * E:
        j = 0
        while C * i + D * j <= F // 100 * E:
            sugar.add(C * i + D * j)
            j += 1
        i += 1

    ph = dict()
    for i in persent(water, sugar):
        ph[i[0]] = i[1], i[2]

    a, b = ph[max(ph)]
    print(a + b, b)

def persent(w, s):
    max_ph = 100 * E / (100 + E)
    for a in w:
        for b in s:
            if 0 < a + b <= F:
                x = 100 * b / (a + b)
                if x <= max_ph:
                    yield x, a, b

main()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans = [100*A, 0]
for a in range(0, F+1, A*100):
    for b in range(0, F+1, B*100):
        for c in range(0, F+1, C):
            for d in range(0, F+1, D):
                water = a+b
                sugar = c+d
                if water+sugar > F or water == 0 or 100*sugar > water*E:
                    break
                else:
                    if ans[1]/(ans[0]+ans[1]) < sugar/(water+sugar):
                        ans = [water, sugar]

print(ans[0]+ans[1], ans[1])

Submission status: Accepted

Solution code:
# Editorial solution for question C

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

waterCombinations = {0}
sugarCombinations = {0}

while True:
    copy = set(waterCombinations)
    for i in copy:
        m = i+a * 100
        n = i+b * 100
        if m <= f:
            waterCombinations.add(m)
        if n <= f:
            waterCombinations.add(n)
    if copy==waterCombinations:
        break

while True:
    copy = set(sugarCombinations)
    for i in copy:
        m = i+c
        n = i+d
        if m <= f:
            sugarCombinations.add(m)
        if n <= f:
            sugarCombinations.add(n)
    if copy==sugarCombinations:
        break


best = 0
bestWater = 1
bestSugar = 1
for i in waterCombinations:
    for j in sugarCombinations:
        maxSugarAllowed = e*(i/100)
        if i+j > 0:
            l = (100 * j) / (i + j)
            if best <= l and j <= maxSugarAllowed and i+j <= f:
                bestWater = i
                bestSugar = j
                best = l
print(bestWater + bestSugar, bestSugar)

Submission status: Accepted

Solution code:

A, B, C, D, E, F = map(int, input().split())
# A:水を100Ag　B:水を100Bg C:砂糖をCg D:砂糖をDg E:100gあたりの溶ける最大量　F:入れられる物質の質量の限界

ans_mizu = 1
ans_sato = 0
pat = []
mizu = set()
for i in range(int(F/100)+1):
    for j in range(int(F/100)+1):
        if 100*A*i + 100*B*j <= F:
            mizu.add(100*A*i+100*B*j)

mizu.remove(0)

for m in mizu:
    howaryo = (m*E)//100
    for i in range(int(howaryo/C)+1):
        for j in range(int(howaryo/D)+1):
            sato = C*i + D*j
            if (m + sato <= F) & (sato <= howaryo):
                ans_sato = max(ans_sato,sato)
                
    pat.append([m+ans_sato,ans_sato])
    ans_mizu = 1
    ans_sato = 0
    
pat.sort(key = lambda x:x[1]/(x[0]+x[1]), reverse = True)
print(pat[0][0],pat[0][1])

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
def FS():
    ans = (100*A,0)
    for a in range(0,F,100*A):
        for b in range(0,F,100*B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat,sug = (a + b),(c + d)
                    if wat == 0 or wat+sug > F or 100*sug > E*wat:
                        break
                    elif 100*sug == E*wat:
                        return (wat,sug)
                    elif sug*ans[0] > ans[1]*wat:
                        ans = (wat,sug)  
    return ans
ans = FS()
print(sum(ans),ans[1])

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
A,B = 100*A,100*B
def ql():
    ans = (0,A)
    for a in range(0,F,A):
        for b in range(0,F,B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat,sug = (a + b),(c + d)
                    if wat+sug > F or 100*sug > E*wat:
                        break
                    elif sug*ans[1] > ans[0]*wat:
                        ans = (sug,wat)  
    return ans
ans = ql()
print("{} {}".format(sum(ans),ans[0]))

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
A,B = 100*A,100*B

def ql():
    ans = (0,A)
    for a in range(0,F,A):
        for b in range(0,F,B):
            for c in range(0,F,C):
                for d in range(0,F,D):
                    wat = (a + b)
                    sug = (c + d)
                    if wat == 0:
                        break
                    if wat+sug > F or 100*sug > E*wat:
                        break
                    elif 100*sug == E*wat:
                        return (sug,wat)
                    elif sug*ans[1] > ans[0]*wat:
                        ans = (sug,wat)  
    return ans
ans = ql()
print(str(ans[0]+ans[1]) + " " + str(ans[0]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc074/tasks/arc083_a
WA
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    A, B, C, D, E, F = map(int, input().split())

    w = []
    s = []
    for i in range(int(F/100/A+1)):
        for j in range(int(F/100/B+1)):
            water = 100*A*i + 100*B*j
            if  water <= F and water > 0:
                w.append(water)

    for i in range(int(F/C+1)):
        for j in range(int(F/D+1)):
            sugar = C*i + D*j
            if sugar <= F and sugar > 0:
                s.append(sugar)

    max_density = (E*100) / (E+100)
    record_density = 0.0
    record = [w[0], 0]
    for i in w:
        for j in s:
            if i+j <= F:
                density = (100 * j) / (i + j)
                if density > record_density and density <= max_density:
                        record_density = density
                        record = [i+j, j]

    print(*record)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
def main():
    a, b, c, d, e, f = [int(i) for i in input().split()]
    #print(a, b, c, d, e, f)
    
    L_UNIT = 100
    result_sw, result_s = 0, 0
    ans = -10000.

    water_list = []
    sugar_list = []

    for t_a in range( int( f / (a * L_UNIT) ) + 1 ):
        #print("a")
        for t_b in range( int( f / (b * L_UNIT) ) + 1 ):
            #print("b")
            #sugar_lim = e * (a * t_a + b * t_b)
            if( (a * t_a * L_UNIT + b * t_b * L_UNIT) <= f ):
                water_list.append(a * t_a * L_UNIT + b * t_b * L_UNIT)
            
    for t_c in range( int( f / c ) + 1 ):
        #print("c")
        for t_d in range( int( f / d ) + 1 ):
            #print("d")
            if( (c * t_c + d * t_d) <= f):
                sugar_list.append( c * t_c + d * t_d )
            
    for water in water_list:
        for sugar in sugar_list:
            sugar_lim = e * (water / L_UNIT)
            if( sugar <= sugar_lim  and 0 < (water + sugar) and (water + sugar) <= f):
                noudo = 100 * sugar / (water + sugar)
                #print(noudo)
                if(ans < noudo):
                    ans = noudo
                    result_sw = sugar + water
                    result_s = sugar
    #print(ans)                    
    print( "{} {}".format(result_sw, result_s) )
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    a, b, c, d, e, f = read_int_list()
    best_water = 100 * a
    best_sugar = 0
    i = 0
    while 100 * i * a <= f:
        j = 0
        while 100 * i * a + 100 * j * b <= f:

            water = 100 * i * a + 100 * j * b
            k = 0
            while water + k * c <= f and k * c <= e * (i * a + j * b):

                l1 = int((f - water - k * c) / d)
                l2 = int((e * (i * a + j * b) - k * c) / d)
                l = min(l1, l2)
                if (i, j, k, l) != (0, 0, 0, 0):
                    if True:
                        # rapide
                        sugar = k * c + l * d
                        total = water + sugar
                        density = sugar / total
                        best_total = best_sugar + best_water
                        best_density = best_sugar / best_total
                        if density > best_density:
                            best_sugar = sugar
                            best_water = water
                    else:
                        # trop lent
                        l = 0
                        while water + k * c + l * d <= f and k * c + l * d <= e * (i * a + j * b):
                            if (i, j, k, l) == (0, 0, 0, 0):
                                continue
                            sugar = k * c + l * d
                            total = water + sugar
                            density = sugar / total
                            best_total = best_sugar + best_water
                            best_density = best_sugar / best_total
                            if density > best_density:
                                best_sugar = sugar
                                best_water = water
                            l += 1
                k += 1
            j += 1
        i += 1

    print(best_water + best_sugar, best_sugar)


main()

Submission status: Accepted

Solution code:
def C_Sugar_Water(A, B, C, D, E, F):
    import itertools
    x = set()  # 水の量が取りうるパターン
    y = set()  # 砂糖の量が取りうるパターン
    for i in range(F):
        for j in range(F):
            tmp = 100 * A * i + 100 * B * j
            if tmp <= F:
                x.add(tmp)
    for i in range(F):
        for j in range(F):
            tmp = i * C + j * D
            if tmp <= F:
                y.add(tmp)

    fill = list(itertools.product(x, y))
    concentration = 0  # 砂糖水の濃度
    for k in fill:
        water = k[0]
        sugar = k[1]

        if water == 0 and sugar == 0:
            # 水も砂糖も入れないパターン
            continue
        elif E * (water // 100) < sugar:
            # 砂糖を溶かしきれない
            continue
        elif water + sugar > F:
            # ビーカーに入れられる質量を超えた
            continue
        else:
            if (100 * sugar) / (water + sugar) >= concentration:
                concentration = (100 * sugar) / (water + sugar)
                ans = (water + sugar, sugar)
    print('{} {}'.format(ans[0], ans[1]))
    return None

A,B,C,D,E,F=[int(i) for i in input().split()]
C_Sugar_Water(A, B, C, D, E, F)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
best_water=0
best_salt=0
best_rate=0
for i in range(30//A+1):#Aの投入数
  for j in range(30//B+1):#Bの投入数
    water=(i*A+j*B)*100
    if water<=F and water:
      max_salt=min(F-(i*A+j*B)*100,(i*A+j*B)*E)
      for k in range(max_salt//C+1):#Cを何個使うか
        l=(max_salt-C*k)//D#Dは何個つかえるか
        salt=k*C+l*D
        rate=100*salt/(water+salt)
        if rate>=best_rate and rate<=E and water+salt<=F:
          best_rate=rate
          best_salt=salt
          best_water=water
print(best_water+best_salt,best_salt)

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]

[a,b,c,d,e,f]=i2()
w=[]
s=[]
for i in range(f+1):
    for j in range(f+1):
        t=(a*i+b*j)*100
        tt=c*i+d*j
        if t<=f:
           w.append(t)
        if tt<=f:
           s.append(tt)
a=0
g=[]
for i in w:
 for j in s:
     if 0<i+j<=f and j<=i*e/100:
        g.append([j*100/(i+j),i+j,j])
g.sort()
print(g[-1][1],g[-1][2])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split(" "))

max = 0
water = 0
sugar = 0
flag = True

i = 1
while(f >= 100 * a * i):
    j = 0
    while(f >= 100 * (a * i + b * j)):
        k = 0
        while(f >= 100 * (a * i + b * j) + c * k):
            l = 0
            while(f >= 100 * (a * i + b * j) + c * k + d * l):
                n = 100 * (c * k + d * l) / (100 * (a * i + b * j) + c * k + d * l)
                if(n > 100 * e / (100 + e)):
                    break
                if(max < n):
                    max = n
                    water = 100 * (a * i + b * j)
                    sugar = c * k + d * l
                l += 1
            k += 1
        j += 1
    i += 1

i = 0
j = 1
while(f >= 100 * (a * i + b * j)):
    k = 0
    while(f >= 100 * (a * i + b * j) + c * k):
        l = 0
        while(f >= 100 * (a * i + b * j) + c * k + d * l):
            n = 100 * (c * k + d * l) / (100 * (a * i + b * j) + c * k + d * l)
            if(n > 100 * e / (100 + e)):
                break
            if(max < n):
                max = n
                water = 100 * (a * i + b * j)
                sugar = c * k + d * l
            l += 1
        k += 1
    j += 1

if(water == 0):
    water = 100 * a
print("%d %d" %(water + sugar, sugar))

Submission status: Accepted

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

ans = [100 * a, 0]
for sg in range(f + 1):
    exist = False
    for kc in range(sg // c + 1):
        if (sg - kc * c) % d == 0 and 0 <= (sg - kc * c) // d:
            exist = True
    if not exist:
        continue
    for sw in range(sg, f + 1, 100):
        exist = False
        for ka in range((sw - sg) // 100 * a + 1):
            kb = (sw - sg - 100 * ka * a) // (100 * b)
            if (sw - sg - 100 * ka * a) % (100 * b) == 0 and 0 <= (sw - sg - 100 * ka * a) // (100 * b):
                exist = True
        if not exist:
            continue
        if (100 + e) * sg <= sw * e and ans[1] * sw < ans[0] * sg:
            ans = [sw, sg]

print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = []
    
    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+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            memo.append([w+s,s])
    
    print(*sorted(memo, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
memo = []

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+s > F:
                    break
                else:
                    if w/100 * E >= s:
                        memo.append([w+s,s])

print(*sorted(memo, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])

Submission status: Accepted

Solution code:
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    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:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100* s/(w+s)
                            memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

def main():
    A, B, C, D, E, F = [int(x) for x in input().split()]
    max_rate = E / (100 + E)
    best_weight, best_suger, best_rate = A*100, 0, 0.0
    for a in range(F//100 +1):
        for b in range((F-a*A)//100 + 1):
            water = (a*A+b*B)*100
            if water > F:
                continue
            for c in range((F-water)//C + 1):
                d = min((F - water - c*C) // D, int((E*water-100*c*C) / (100*D)))
                if d < 0:
                    continue
                suger = c*C + d*D
                if water + suger > F:
                    continue
                if water + suger == 0:
                    rate = 0.0
                else:
                    rate = suger / (water + suger)
                if rate > max_rate:
                    continue
                if rate > best_rate:
                    best_weight = water + suger
                    best_suger = suger
                    best_rate = rate
    print(best_weight, best_suger)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    if a == 0 and b == 0:
                        break
                    if (100*A)*a + (100*B)*b + C*c + D*d > F:
                        break
                    if  ((100*A)*a + (100*B)*b)/100 *E < C*c + D*d:
                        break
                    density = 100 * (C*c+D*d) / ( (100*A)*a + (100*B)*b + C*c + D*d )
                    memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())

ans = []
for ai in range(31):
    for bi in range(31):
        for ci in range(101):
            for di in range(101):
                ab = ai*A*100 + bi*B*100
                cd = ci*C + di*D
                if ab + cd > F:
                    break
                else:
                    if (ab/100) * E >= cd:
                        ans.append([ab + cd, cd])
print(*sorted(ans, key=lambda x: (100*x[1] / x[0] if x[0] else 0))[-1])

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

def solution(A, B, C, D, E, F):
    max_percentage = -1
    mass = 0
    mass_sugar = 0

    for c in xrange(0, int(F/C) + 1):
        if (c * C) > F:
            break

        for d in xrange(0, int(F/D) + 1):
            sugar = c * C + d * D
            if sugar > F:
                break

            for a in xrange(0, int(F/A) + 1):
                if (sugar + 100 * a * A) > F:
                    break

                for b in xrange(0, int(F/B) + 1):
                    water = 100 * a * A + 100 * b * B
                    if (sugar + water) > F:
                        break
                    elif (sugar + water) == 0:
                        continue

                    if sugar <= (int(water / 100) * E):
                        if water > 0:
                            percentage = float(sugar) / water * 100
                        else:
                            percentage = 0

                        if percentage > max_percentage:
                            mass = sugar + water
                            mass_sugar = sugar
                            max_percentage = percentage

                        if max_percentage == 100:
                            return mass, mass_sugar

    return mass, mass_sugar

def main(argv):
    line = sys.stdin.readline()

    while line:
        A, B, C, D, E, F = map(int, line.rstrip("\n").split(" ", 6))

        mass, mass_sugar = solution(A, B, C, D, E, F)
        print("{0} {1}".format(mass, mass_sugar))

        exit(0)
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = [int(v) for v in input().split()]
# print(A, B, C, D, E, F)
An = [(100*A)*(v) for v in range(int(F/(100*A))+1)]
Bn = [(100*B)*(v) for v in range(int(F/(100*B))+1)]
# print(An, Bn, 1)
 
 
def per1(RE):
  Cn = [C*v for v in range(int(RE/C)+1)]
  Dn = [D*v for v in range(int(RE/D)+1)]
  rtn = 0
  for v2 in Cn:
    for w2 in Dn:
      r = v2 + w2
      if rtn < r <= RE:
        rtn = r
  return rtn
  
  
max_suger_per = 0
max_water = 0
max_suger = 0
for v in Bn:
  for w in An:
    s = v + w
    if s > F or s == 0: continue
    re = int(s * E / 100)
    if s + re > F: re = F - s
    # print(s, re)
    result = per1(re)
    # print(result)
    suger = (100 * result) / (s + result)
    if suger > max_suger_per:
      max_suger_per = suger
      max_water = s + result
      max_suger = result
    
if max_water == 0:
  max_water = An[1]
print(max_water, max_suger)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,raw_input().split(' '))

w_m=0
w_t=0
s_m=0

a_max=F/(100*A)
b_max=F/(100*B)

def sugar(w):
    c_max=(F-w)/C
    d_max=(F-w)/D
    m=0
    for c in range(0,c_max+1):
        for d in range(0,d_max+1):
            if (C*c+D*d)>E*w/100. or (C*c+D*d)+w>F:
                continue
            elif (C*c+D*d)>m:
                m=(C*c+D*d)
    return m

m=0.
for a in range(0,a_max+1):
    for b in range(0,b_max+1):
        w=100*(A*a+B*b)
        if w>w_t and w<F:
            w_t=w
        if w>F:
            continue
        s=sugar(w)
        if (w+s)==0 or w+s>F:
            continue
        elif 100.*s/(w+s)>m:
            m=100.*s/(w+s)
            w_m=w
            s_m=s

if w_m==0 and s_m==0:
    print w_t,0
else:
    print int(w_m+s_m),s_m