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

Solution (Python):
def main():
    a, b, c, d, e, f = [int(i) for i in input().split()]
    
    
    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 ):
        
        for t_b in range( int( f / (b * L_UNIT) ) + 1 ):
            
            
            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 ):
        
        for t_d in range( int( f / d ) + 1 ):
            
            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)
                
                if(ans < noudo):
                    ans = noudo
                    result_sw = sugar + water
                    result_s = sugar
    
    print( "{} {}".format(result_sw, result_s) )
    
if __name__=="__main__":
    main()

Solution (Python):
import sys




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:
                        
                        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:
                        
                        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()

Solution (Python):
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)

Solution (Python):
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):
  for j in range(30//B+1):
    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):
        l=(max_salt-C*k)//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)

Solution (Python):
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])

Solution (Python):
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))

Solution (Python):
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)))

Solution (Python):
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()

Solution (Python):
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])

Solution (Python):
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()

Solution (Python):



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()

Solution (Python):
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()

Solution (Python):
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])

Solution (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)

Solution (Python):
A, B, C, D, E, F = [int(v) for v in input().split()]

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)]

 
 
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
    
    result = per1(re)
    
    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)

Solution (Python):
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

Solution (Python):
a, b, c, d, e, f = [int(x) for x in input().strip().split()]
a *= 100
b *= 100

water_cands = set()
t = 0
while t <= f:
    water_cands.add(t)
    u = t + b
    while u <= f:
        water_cands.add(u)
        u += b
    t += a

rat, wat, sug = 0.0, a, 0
for w in water_cands:
    if w == 0:
        continue
    suger_limit = min(f - w, w // 100 * e)
    suger_max = 0
    t = 0
    while t <= suger_limit:
        if suger_max < t:
            suger_max = t
        u = t + d
        while u <= suger_limit:
            if suger_max < u:
                suger_max = u
            u += d
        t += c
    if suger_max / (suger_max + w) > rat:
        rat = suger_max / (suger_max + w)
        wat = w
        sug = suger_max

print(wat + sug, sug)

Solution (Python):
if __name__ == '__main__':
    A, B, C, D, E, F = list(map(int, input().split()))

    
    a_plus_b = set()
    for i in range(0, 31, A):
        for j in range(0, 31, B):
            if not (i == 0 and j == 0):
                if i + j <= 30:
                    a_plus_b.add(i + j)

    c_plus_d = set()
    for i in range(0, F, C):
        for j in range(0, F, D):
            if i + j <= F:
                c_plus_d.add(i + j)

    max_concent = -1
    ans_sum = 0
    ans_sugar = 0
    
    
    for cd in c_plus_d:
        for ab in a_plus_b:
            if cd <= E * ab and cd <= F - 100 * ab:
                if max_concent <= cd / ab:
                    max_concent = cd / ab
                    ans_sum = 100 * ab + cd
                    ans_sugar = cd

    print(str(ans_sum) + " " + str(ans_sugar))

Solution (Python):


inlist = list(map(int, input().split()))
a = inlist[0] * 100
b = inlist[1] * 100
c = inlist[2]
d = inlist[3]
e = inlist[4]
f = inlist[5]

tupleList = []

for i in range((f//a) + 1):
    for j in range((f - a*i)//b + 1):
        for k in range((f - a*i - b*j)//c + 1):
            for l in range((f - a*i - b*j - c*k)//d + 1):
                if (c*k + d*l)*(100 + e) <= (a*i + b*j + c*k + d*l)*e:
                    tupleList.append([i, j, k, l])
tupleList.remove([0, 0, 0, 0])

def concentration(i, j, k, l):
    return (c*k + d*l)/(a*i + b*j + c*k + d*l)

max_con = concentration(tupleList[0][0], tupleList[0][1], tupleList[0][2], tupleList[0][3])
max_tuple = tupleList[0]

for i in range(len(tupleList) - 1):
    if max_con < concentration(tupleList[i+1][0], tupleList[i+1][1], tupleList[i+1][2], tupleList[i+1][3]):
        max_con = concentration(tupleList[i + 1][0], tupleList[i + 1][1], tupleList[i + 1][2], tupleList[i + 1][3])
        max_tuple = tupleList[i + 1]

print(str(a*max_tuple[0] + b*max_tuple[1] + c*max_tuple[2] + d*max_tuple[3]) \
      + " " + str(c*max_tuple[2] + d*max_tuple[3]))

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

water = [1]
for i in range(30):
	water.append(0)

for i in range(31):
	if water[i] == 1:
		if (i + A) * 100 <= F:
			water[i + A] = 1

		if (i + B) * 100 <= F:
			water[i + B] = 1

K = []

for i in range(1, 31):
	if water[i] == 1:
		sugar = [1]
		X = min(i * E, F - 100 * i)
		for j in range(X):
			sugar.append(0)

		for j in range(X + 1):
			if sugar[j] == 1:
				if j + C <= X:
					sugar[j + C] = 1

				if j + D <= X:
					sugar[j + D] = 1
		sugar.reverse()
		s = sugar.index(1)
		WS = ((100 * (X - s) / (100 * i + X - s)), 100 * i + X - s, X - s)
		K.append(WS)

K = sorted(K)
print(K[-1][1], K[-1][2])

Solution (Python):
x_list = input().split()
a = 100*int(x_list[0])
b = 100*int(x_list[1])
c = int(x_list[2])
d = int(x_list[3])
e = int(x_list[4])
f = int(x_list[5])

max_sato = e*f/100//1
max_mizu = f

def all_pattern(a,b,c):
    max_a = int(c//a)
    all_list = []
    for i in range(max_a+1):
        goukei = 0
        goukei += a*i
        j = 0
        while goukei <= c:
            if not goukei in all_list:
                all_list.append(goukei)
            goukei += b
    return all_list

mizu_pattern = all_pattern(a,b,max_mizu)
sato_pattern = all_pattern(c,d,max_sato)

satosui_situryo = 0
sato_situryo = 0
max_noudo = 0

for mizu in mizu_pattern:
    for sato in sato_pattern:

        if sato + mizu > 0:
            tmp_noudo = sato/(sato+mizu)*100

            if max_noudo < tmp_noudo and tmp_noudo <= e/(100+e)*100 and mizu+sato <= f:
                max_noudo = tmp_noudo
                satosui_situryo = mizu + sato
                sato_situryo = sato


if satosui_situryo == 0:
    satosui_situryo += a

print(satosui_situryo,sato_situryo)

Solution (Python):
A,B,C,D,E,F=[int(x) for x in input().split()]
from itertools import product
def gauss(i):
    return F//i+1
waters=set()
sugers=set()
ans={"water":100*A,"suger":0}
for a,b in product(range(gauss(A)),range(gauss(B))):
    waters.add(100*(a*A+b*B))
for c,d in product(range(gauss(C)),range(gauss(D))):
    sugers.add(c*C+d*D)
for water in sorted(waters):
    if water==0:
        continue
    for suger in sorted(sugers):
        if water+suger>F:
            break
        if 100*suger>E*water:
            break
        if ans["suger"]*(water+suger)<suger*ans["water"]:
            ans={"water":water+suger,"suger":suger}
print(ans["water"],ans["suger"])

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

y = 0
yx = 100*A
ys= 0
W = {}
for a in range(F//100 + 1):
    for b in range(F//200 + 1):
        w = 100*A*a + 100*B*b
        if w <= F:
            W[w] = 0
        
for w in W.keys():
    for c in range(min(F-w, (E*w//100)) + 1):
        for d in range(min(F-w, (E*w//100))//2 + 1):
            s = C*c + D*d
            x = w + s
            try:
                if s+w <= F and s/x <= E/(100+E):
                    if s/x > y:
                        y = s/x
                        ys = s
                        yx = x
            except ZeroDivisionError:
                pass
                
print(yx, ys)

Solution (Python):

A,B,C,D,E,F = map(int, input().split(' '))
water = []
for i in range(int(F/(A*100))+1):
    for j in range(int(F/(B*100))+1):
        water.append(100*A*i+100*B*j)
water = list(set(water))
water = sorted(water)
water = [i for i in water if i <= F]
water = water[::-1]
water.remove(0)

suger = []
for i in range(int(F/C)+1):
    for j in range(int(F/D)+1):
        suger.append(C*i+D*j)
suger = list(set(suger))
suger = sorted(suger)
suger = [i for i in suger if i <= F]
suger = suger[::-1]

limit = E / (100.0+E)
maxAns = 0.0
for w in water:
    for s in suger:
        if s + w > F:
            continue
        tmp = s / float(s+w)
        if tmp <= limit and tmp >= maxAns:
            maxAns = tmp
            maxWS = w+s
            maxS = s
print(str(maxWS) + ' ' + str(maxS))

Solution (Python):

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


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def get_composable_numbers(a, b, lim):
    result = set()
    result.add(0)
    if a < lim:
        result.add(a)
    if b < lim:
        result.add(b)

    for c in range(max(result), lim + 1):
        if (c - a) in result or (c - b) in result:
            result.add(c)

    return list(result)

def get_concentration(water, suger):
    return suger / (water + suger)

def max_below(array, limit):
    max_res = array[0]
    for elem in array:
        if elem > max_res and elem <= limit:
            max_res = elem
        elif elem >= limit:
            break

    return max_res

def main():
    a, b, C, D, E, F = get_ln_int_inputs()
    A = 100 * a
    B = 100 * b
    water_composables = sorted(list(map(lambda x: x * 100, get_composable_numbers(a, b, F // 100))))
    suger_composables = sorted(get_composable_numbers(C, D, (E * F) // 100))

    res_tuple = (A, 0)
    max_concentration = 0
    for i in range(1, len(water_composables)):
        water = water_composables[i]
        suger_max = max_below(suger_composables, min((water * E) // 100, F - water))
        mass = water + suger_max

        concentration = get_concentration(water, suger_max)
        if concentration > max_concentration:
            max_concentration = concentration
            res_tuple = (water + suger_max, suger_max)
    
    print(str(res_tuple[0]) + " " + str(res_tuple[1]))
    return

main()

Solution (Python):


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

alpha = E/(100.0+E) 


sugar_limit = 0 

a = b = c = d = 0
a_max = F // (100*A)
b_max = F // (100*B)



water_pattern = []
for i in range(a_max+1):
    for j in range(b_max+1):
        water_pattern.append(100*A*i + 100*B*j)


max_density = -1.0
ans_water = 0.0
ans_sugar = 0.0
for water_amount in water_pattern:
    if water_amount > F:
        continue
    sugar_limit = water_amount * (E/100)
    
    c_max = (F-water_amount) // C
    d_max = (F-water_amount) // D
    max_sugar_amount = -1.0
    sugar_pattern = []
    '''
    for i in range(c_max+1):
        for j in range(d_max+1):
            sugar_pattern.append(C*i + D*j)
    for sugar_amount in sugar_pattern:
        if sugar_amount > sugar_amount
    '''
    for i in range(c_max+1):
        for j in range(d_max+1):
            sugar_amount = C*i + D*j
            if sugar_amount > sugar_limit or (sugar_amount+water_amount) > F:
                continue
            max_sugar_amount = max(max_sugar_amount, sugar_amount)
    density = -1.0
    if water_amount+max_sugar_amount > 0:
        density = (100*max_sugar_amount) / (water_amount+max_sugar_amount)
    else:
        continue
    if max_density < density:
        max_density = density
        ans_water = water_amount
        ans_sugar = max_sugar_amount

print((ans_water+ans_sugar), ans_sugar)

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

counter = []

cnta = 1
cntb = 0
while (cnta * A) <= F:
  while (cnta * A + cntb * B) <= F:
    counter.append([cnta, cntb])
    cntb += 1
  cnta += 1
  cntb = 0

water = []
for c in counter:
  water.append(c[0] * A + c[1] * B)
water = list(set(water))

def sugar(water,C,D,E,F):
  sugar = []
  limit = water / 100 * E
  cntc = 0
  cntd = 0
  while cntc * C <= limit and cntc * C + water <= F:
    while cntc * C + cntd * D <= limit and cntc * C + cntd * D + water <= F:
      sugar.append(cntc * C + cntd * D)
      cntd += 1
    cntc += 1
    cntd = 0
  return max(sugar)

maxconc = [0,0,-1]
for w in water:
  s = sugar(w,C,D,E,F)
  conc = s/(w+s)
  if conc > maxconc[2]:
    maxconc = [w+s, s, conc]

print(" ".join(map(str, maxconc[0:2])))

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

ws = set()
i = j = 0
while True:
    j = 0
    if B*i > F//100: break
    while True:
        w = B*i + A*j
        if w > F//100: break
        ws.add(w)
        j += 1
    i += 1
ws = list(ws)
ws.sort()

ss = set()
i = j = 0
while True:
    j = 0
    if D*i > F: break
    while True:
        s = D*i + C*j
        if s > F: break
        ss.add(s)
        j += 1
    i += 1
ss = list(ss)
ss.sort()

limit = E / (100+E)
water = A*100
sugar = rate = 0
for w in ws:
    w = w*100
    if w == 0: continue
    if w > F: break
    for s in ss:
        if w+s > F: break
        r = s / (w+s)
        if r > limit: break
        if r > rate:
            rate = r
            water = w
            sugar = s
print(water+sugar, sugar)

Solution (Python):
import math
A,B,C,D,E,F = map(int, input().split())
result_noudo=None
result_satosui=None
result_sato=None

for a in range(math.floor(F/100*A)+1):
    for b in range(math.floor((F-100*A*a)/100*B)+1):
        for c in range(math.floor((F-100*A*a-100*B*b)/C)+1):
            for d in range(math.floor((F-100*a*A-100*b*B-C*c)/D)+1):
                sum_under=100*a*A+100*b*B+C*c+D*d
                if (a==0 and b==0) or (d==0 and c==0):
                    continue
                sum_top=C*c+D*d
                noudo=(100*sum_top)/sum_under
                if sum_under<=F and noudo<=(100*E)/(100+E) and (result_noudo==None or noudo>result_noudo):
                    result_noudo=noudo
                    result_satosui=sum_under
                    result_sato=sum_top
if result_noudo==None:
    result_satosui=100*A
    result_sato=0
print(str(result_satosui)+" "+str(result_sato))

Solution (Python):
import sys


def read_numbers():
    return [int(num) for num in sys.stdin.readline().split()]
def read_string():
    return sys.stdin.readline().rstrip('\r\n')
def list2str(*array):
    return ' '.join([str(i) for i in array])

def main(nums):
    A, B, C, D, E, F = nums
    def density(sugar, water):
        if sugar + water == 0:
            return 0.0
        return sugar / (sugar + water)
    cache = {}
    def recurse(sugar, water):
        if (sugar, water) in cache:
            return cache[(sugar, water)]
        if sugar + water > F:
            return (0.0, 0, 0)
        if density(sugar, water) > density(E, 100):
            return (0.0, 0, 0)
        result = max(
            (density(sugar, water), sugar, water),
            recurse(sugar, water+100*A),
            recurse(sugar, water+100*B),
            recurse(sugar+C, water),
            recurse(sugar+D, water),
        )
        cache[(sugar, water)] = result
        return result
    dens, sugar, water = recurse(0,0)
    return "%d %d" % (sugar+water, sugar)




def parse_stdin():
    
    
    
    
    nums = read_numbers()
    return nums

def test_main():
    """run pytest stdin.py to test"""
    assert main([17, 19, 22, 26, 55, 2802]) == "2634 934"

if __name__ == '__main__':
    nums = parse_stdin()
    result = main(nums)
    print(result)

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


water = set([])
sugar = set([])
max_all = f / 100
a_count = int(max_all // a)


for i in range(a_count + 1):
    
    j = 0
    while(True):
        if i == 0 and j == 0:
            j += 1
        if i*a + j*b <= max_all:
            water.add(i*a + j*b)
        else:
            break
        j += 1

c_count = int(f // c)

for i in range(c_count + 1):
    j = 0
    while(True):
        if i*c + j*d <= f:
            sugar.add(i*c + j*d)
        else:
            break
        j += 1

all_water = 0
all_sugar = 0
percent = 0

for i in water:
    for j in sugar:
        if j / (i*100 + j) <= e / (100 + e) and 100*i + j <= f:
            if percent <= j / (i*100 + j):
                all_water = (i*100 + j)
                all_sugar = j
                percent = j / (i*100 + j)

print(all_water, all_sugar)