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



MAX_K = 5000

ans = -1
tot = -1
rate = -1
F = [False] * MAX_K
G = [False] * MAX_K

if __name__ == "__main__":
    global a, b, c, d, e, f
    a, b, c, d, e, f = map(int, input().split())
    F[0] = True
    G[0] = True
    for i in range(0, f):
        if F[i]:
            if i + a <= f:
                F[i + a] = True
            if i + b <= f:
                F[i + b] = True
        if G[i]:
            if i + c <= f:
                G[i + c] = True
            if i + d <= f:
                G[i + d] = True
    i = 1
    while i * 100 <= f:
        if F[i]:
            j = 0
            while i * 100 + j <= f and j <= i * e:
                if G[j]:
                    r = 100.0 * j / (i * 100.0 + j)
                    if r > rate:
                        rate = r
                        tot = i * 100 + j
                        ans = j
                j += 1
        i += 1
    print(" ".join(map(str, (tot, ans))))

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
conc = 0.0
liq,sug = 100*A,0
for a in range(1 + F//(100*A)):
  for b in range(1 + (F-100*A*a)//(100*B)):
    if a + b < 1 or F <= 100*(A*a + B*b):
      break
    for c in range(1 + min(((A*a+B*b)*E)//C,F-100*(A*a+B*b))):
      for d in range(1 + min(((A*a+B*b)*E-C*c)//D,F-100*(A*a+B*b)-C*c)):
        tmp_sug = C*c+D*d
        tmp = 100*(A*a+B*b)+tmp_sug
        if tmp <= F and tmp_sug <= (A*a+B*b)*E and conc < (100*tmp_sug/tmp):
          conc = (100*tmp_sug/tmp)
          liq = tmp
          sug = tmp_sug
print(liq,sug)

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

water_mass = []
for i in range(f // (100 * b) + 1):
	for j in range(f // (100 * a) + 1):
		if 0 < 100 * b * i + 100 * a * j <= f and 100 * b * i + 100 * a * j not in water_mass:
			water_mass.append(100 * b * i + 100 * a * j)

ans_gross = 100 * a
ans_sugar = 0
c_max = 0
c_lim = e / (100 + e)

for water in water_mass:
	for i in range((f - water) // d + 1):
		for j in range((f - water - i * d) // c + 1):
			if i != 0 or j != 0:
				if c_max < (j * c + i * d) / (j * c + i * d + water) <= c_lim:
					c_max = (j * c + i * d) / (j * c + i * d + water)
					ans_sugar = j * c + i * d 
					ans_gross = ans_sugar + water

print(ans_gross, ans_sugar)

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

water_sugar = []
sugar_best = []
s = 0
max_sugar = 0

for a in range(0,31):
    water = A*a
    sugar = E*water
    if water==0:
        pass
    elif (water*100)>F:
        break
    elif (water*100)+sugar>F:
        s = F-(water*100)
        water_sugar.append([water*100,s])
    elif (water*100)+sugar<=F:
        s = sugar
        water_sugar.append([water*100,s])
    if s>max_sugar: max_sugar=s
    for b in range(1,31):
        water += B
        sugar = E*water
        if (water*100)>F:
            break
        elif (water*100)+sugar>F:
            s = F-(water*100)
            water_sugar.append([water*100,s])
        elif (water*100)+sugar<=F:
            s = sugar
            water_sugar.append([water*100,s])
        if s>max_sugar: max_sugar=s
        




sugar = []
c=0
while(True):
    s = c*C
    if s<=max_sugar:
        sugar.append(s)
    else:
        break
    while(True):
        s += D
        if s<=max_sugar:
            sugar.append(s)
        else:
            break
    c+=1
sugar = sorted(sugar,reverse=True)



for ws in water_sugar:
    for s in sugar:
        if s<=ws[1]: break
    ws[1] = s
    sugar_best.append((100*ws[1])/(ws[0]+ws[1]))
    
best = water_sugar[sugar_best.index(max(sugar_best))]

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

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

water_sugar = []
sugar_best = []

for a in range(0,31):
    water = A*a
    sugar = E*water
    if water==0:
        pass
    elif (water*100)>F:
        break
    elif (water*100)+sugar>F:
        water_sugar.append([water*100,F-(water*100)])
    elif (water*100)+sugar<=F:
        water_sugar.append([water*100,sugar])
    for b in range(1,31):
        water += B
        sugar = E*water
        if (water*100)>F:
            break
        elif (water*100)+sugar>F:
            water_sugar.append([water*100,F-(water*100)])
        elif (water*100)+sugar<=F:
            water_sugar.append([water*100,sugar])



for ws in water_sugar:
    sugar = []
    c=0
    while(True):
        s = c*C
        if s<=ws[1]:
            sugar.append(s)
        else:
            break
        while(True):
            s += D
            if s<=ws[1]:
                sugar.append(s)
            else:
                break
        c+=1
    ws[1] = max(sugar)
    sugar_best.append((100*ws[1])/(ws[0]+ws[1]))
    
best = water_sugar[sugar_best.index(max(sugar_best))]

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

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

noudo=0
mizu=100*a
satou=0

an=int(f/100*a)+2

for i in range(an):
  bn=int((f-100*a*i)/(100*b))+2
  
  for j in range(bn):
    cn=int((f -100*a*i -100*b*j)/c)+2
    
    for k in range(cn):
      dn=int((f -100*a*i -100*b*j -c*k)/d)+2
      
      for l in range(dn):
        
        if 100*i*a + 100*j*b + k*c + l*d != 0 and 100*i*a + 100*j*b + k*c + l*d <= f:
          if noudo <  100*(k*c+l*d)/ (100*i*a + 100*j*b + k*c + l*d) <= 100*e/(100+e):
            noudo = 100 * (k*c+l*d) / (100*i*a + 100*j*b + k*c + l*d)
            mizu = 100*i*a + 100*j*b
            satou =  k*c+l*d

print(mizu+satou, satou)

Solution (Python):


import sys, math, copy




MOD = 10 ** 9 + 7
HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    def mass_water(n, m):
        return 100 * n * a + 100 * m * b

    def mass_sugar(k, l):
        return k * c + l * d

    def mass(n, m, k, l):
        return mass_water(n, m) + mass_sugar(k, l)

    def is_within_f(ms, mw):
        return ms + mw <= f

    def is_within_e(ms, mw):
        return ms * 100 <= mw * e

    def density(ms, mw):
        return ms / mw

    a, b, c, d, e, f = map(int, input().split())
    max_n = f // (100 * a)
    max_m = f // (100 * b)
    max_sugar = f * e / 100.0
    max_k = math.ceil(max_sugar // c)
    max_l = math.ceil(max_sugar // d)

    mass_water_set = set()
    for n in range(max_n + 1):
        for m in range(max_m + 1):
            mw = mass_water(n, m)
            if n + m > 0 and is_within_f(0, mw):
                mass_water_set.add(mw)
    mass_sugar_set = set()
    for k in range(max_k + 1):
        for l in range(max_l + 1):
            mass_sugar_set.add(mass_sugar(k, l))


    max_density = -HUGE
    max_mw = 0
    max_ms = 0
    for mw in mass_water_set:
        for ms in mass_sugar_set:
            if not (is_within_f(ms, mw) and is_within_e(ms, mw)):
                continue
            den = density(ms, mw)
            if den > max_density:
                max_density = den
                max_mw = mw
                max_ms = ms

    print(max_mw + max_ms, max_ms)

main()

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

for i in range(F // A+1):
    for j in range(F // B+1):
        w = A * i + B * j
        if w <= F:
            W.add(w)

for i in range(F // C+1):
    for j in range(F // D+1):
        s = C * i + D * j
        if s <= F:
            S.add(s)

max_rat = -24
for w in W:
    for s in S:
        if w + s <= F and s <= w / 100 * E and s+w!=0:
            rat = s / (s + w)
            if rat > max_rat:
                x, y, max_rat = w, s, rat

print(x + y, y)

Solution (Python):


a,b,c,d,e,f=map(int,raw_input().split())
x=1
y=-1
for i in xrange(0,f+1,100*a):
 for j in xrange(0,f+1-i,100*b):
  s=min(f-i-j,(i+j)*e//100)
  if i+j==0:
   continue
  for k in xrange(0,s+1,c):
   for l in xrange(0,s+1-k,d):
    if 1.0*y/x<1.0*(k+l)/(i+j):
     x=i+j
     y=k+l
print x+y,y

Solution (Python):


a,b,c,d,e,f=map(int,input().split())
x=1
y=-1
for i in range(0,f+1,100*a):
 for j in range(0,f+1-i,100*b):
  s=min(f-i-j,(i+j)*e//100)
  if i+j==0:
   continue
  for k in range(0,s+1,c):
   for l in range(0,s+1-k,d):
    if y/x<(k+l)/(i+j):
     x=i+j
     y=k+l
print(x+y,y)

Solution (Python):


'''
戦略
すべてのパターンをfor文で回す
'''

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

V = []
max_water = 0
max_sato = 0
max_ratio = -1

maxA = F//(100*A)
maxB = F//(100*B)

waters = set()

for i in range(0, maxA+1):
    for j in range(0, maxB+1):
        water = 100*A*i + 100*B*j
        waters.add(water)

maxC = F // C
maxD = F // D
satos = set()
for k in range(0, maxC+1):
    for l in range(0, maxD+1):
        sato = C*k + D*l
        satos.add(sato)

for water in waters:
    for sato in satos:
        if water+sato > F or water+sato == 0:
            continue
        if sato > water/100 * E:
            continue
        
        ratio = sato/(water+sato)*100
        if ratio > max_ratio:
            max_water = water+sato
            max_sato = sato
            max_ratio = ratio
print(max_water, max_sato)

Solution (Python):


input=raw_input()
list=input.split(" ")
for i in range(len(list)):
    list[i]=int(list[i])

e=list[4]
f=list[5]





listx=[]
a=list[0]
b=list[1]

i=0
while True:
   if i*a*100>f:
       break
   j=0
   while True:
      x=i*a*100+j*b*100
      if x>f:
          break;
      if x==0:
          j+=1
          continue;
      if x not in listx:
          listx.append(int(x))
      j+=1 
   i+=1 


listy=[]
c=list[2]
d=list[3]


f2=f*e/(100.0+e)

i=0
while True:
   if i*c>f2:
       break
   j=0
   while True:
      y=i*c+j*d
      if y>f2:
          break;
      if y not in listy:
          listy.append(int(y))
      j+=1 
   i+=1 


lengthx=len(listx)
lengthy=len(listy)

xy_max=0
y_max=0
noudo_max=0

for i in range(lengthx):
    for j in range(lengthy):
        x=listx[i]
        y=listy[j]
        if x+y>f:
            continue
        if float(y)*100/float(x)<=e:
            noudo=float(y)/(x+y)
            if noudo>=noudo_max:
                xy_max=x+y
                y_max=y
                noudo_max=noudo

message=str(xy_max)+" "+str(y_max)
print message

Solution (Python):
a,b,c,d,e,f = [int(n) for n in input().split(" ")]
dp = [-1 for n in range(f + 1)]
dp[0] = 0
for i in range(1530):
    next_dp = dp[:]
    for i,sugar in enumerate(dp):
        if sugar >= 0:
            if i + 100 * a <= f:
                next_dp[i + 100 * a] = sugar
            if i + 100 * b <= f:
                next_dp[i + 100 * b] = sugar
            if i + c <= f and ((i - sugar) * e) / 100 >= sugar + c:
                next_dp[i + c] = max(dp[i + c], sugar + c)
            if i + d <= f and ((i - sugar) * e) / 100 >= sugar + d:
                next_dp[i + d] = max(dp[i + d], sugar + d)
    dp = next_dp
answer = [0,0]
for i,d in enumerate(dp):
    if i != 0 and answer[1] <= d / i:
        answer = [i,d / i]
print(answer[0],round(answer[0] * answer[1] ))

Solution (Python):
import numpy as np

def ceil(a):
    return int(np.ceil(a))

def sol2():
    A,B,C,D,E,F = map(int, input().split(' '))
    na, nb, nc, nd = ceil(F/A/100),ceil(F/B/100),ceil(E*F/C/100),ceil(E*F/D/100) 
    sug = np.arange(0,nc).reshape(1,1,nc,1)*C+np.arange(0,nd).reshape(1,1,1,nd)*D
    wat = np.arange(0,na).reshape(na,1,1,1)*A*100+np.arange(0,nb).reshape(1,nb,1,1)*B*100
    sug2=np.unique(sug[sug<=F*F/100])
    wat2=np.unique(wat[wat<=F])
    
    if len(wat2)==1:
        print(0,0)
        return
    elif E==0:
        print(wat2[1],0)
        return
    
    tot =  wat2[1:].reshape(len(wat2[1:]),1) + sug2
    e2 = E/(100+E)
    dense = (sug2/tot)[tot<=F]
    
    maxi = np.argmax(dense[dense<=e2])
    stot = tot[tot<=F][dense<=e2]
    ssug = (sug2 + tot*0)[tot<=F][dense<=e2]
    
    if dense[maxi] ==0:
        print(wat2[1],0)
    else:
        print(int(stot[maxi]),int(ssug[maxi]))
sol2()

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

w = [i+j for i in range(0,f+1,100*a) for j in range(0,f+1,100*b) if i+j <= f]
s = [i+j for i in range(0,f+1,c) for j in range(0,f+1,d) if i+j <= f]

W = w[-1]
S = 0
for ww in w :
    for ss in s :
        if ww+ss > f or ww == 0:
            continue
        elif ss/(ss+ww) > S/(W+S) and e >= 100*ss/ww:
            W = ww
            S = ss

print(W+S, S)

Solution (Python):
lists = [int(i) for i in input().rstrip().split(" ")]
w_1 = 100 * lists[0]
w_2 = 100 * lists[1]
s_1 = lists[2]
s_2 = lists[3]
sol = lists[4] / (100 + lists[4])
limit = lists[5]

weight = 0
dens = 0
ans = (1,-1)
w_group = set()

for i in range(limit//w_1 + 1):
    for j in range((limit-w_1*i)//w_2 + 1):
        w_group.add(w_1*i + w_2*j)
w_group.remove(0)

s_group = set()

for w_w in w_group:
    for i in range((limit-w_w)//s_1 + 1):
         for j in range((limit-w_w-s_1*i)//s_2 + 1):
             s_group.add(s_1*i + s_2*j)
    for s_s in s_group:
        weight = w_w + s_s
        dens = s_s / weight
        if sol >= dens > ans[1]/ans[0]:
            ans = (weight, s_s)
    s_group.clear()
print("{0} {1}".format(ans[0], ans[1]))

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

max_density = 0
ans_water = 0
ans_sugar = 0
for na in range(F // (A * 100) + 1):
    for nb in range(F // (B * 100) + 1):
        water = (A * na + B * nb) * 100
        if water == 0 or water > F:
            break

        for nc in range(F // C + 1):
            for nd in range(F // D + 1):
                sugar = C * nc + D * nd
                if water + sugar > F:
                    break

                density = sugar / (water + sugar)
                if density > E / (100 + E):
                    break

                if density >= max_density:
                    max_density = density
                    ans_water = water
                    ans_sugar = sugar

print(ans_water + ans_sugar, ans_sugar)

Solution (Python):



cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume * 100 <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = min(water_volume * max_density, max_volume - water_volume * 100)
    for spoons1_nr in range(0, 1 + curr_optimal_sugar // spoon1):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density > global_dencity:
            
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

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

a = int(F/A)
b = int(F/B)

hoge = 0

water = [[0 for i in range(a+1)]for i in range(b+1)]
sugar = [[0 for i in range(a+1)]for i in range(b+1)]

noudo = [[0 for i in range(a+1)]for i in range(b+1)]

for i in range(a+1):
    for j in range(b+1):
        if A*i+B*j < F:
            water[j][i] = A*i+B*j
       


        c = int(E*water[j][i]/(100*C))
        d = int(E*water[j][i]/(100*D))
        for k in range(c+1):
            for m in range(d+1):
                if C*k+D*m <= F-water[j][i]  and C*k+D*m <= E*water[j][i]/100:
                    sugar[j][i] = max(sugar[j][i],C*k+D*m)

for i in range(a+1):
    for j in range(b+1):
        if water[j][i] != 0 and sugar[j][i] != 0:
            noudo[j][i] = sugar[j][i]/(water[j][i]+sugar[j][i])
        if hoge <= noudo[j][i]:
            res_i = i
            res_j = j
            hoge = noudo[j][i]

print(water[res_j][res_i]+sugar[res_j][res_i],sugar[res_j][res_i])

Solution (Python):
A,B,C,D,E,F=map(int,input().split())
x=1
y=-1
for a in range(0,F+1,100*A):
    for b in range(0,F-a+1,100*B):
        m=min(F-a-b,(a+b)*E//100)
        if a+b==0:
            continue
        for c in range(0,m+1,C):
            for d in range(0,m-c+1,D):
                if y/x<(c+d)/(a+b):
                    x=a+b
                    y=c+d
print(x+y,y)

Solution (Python):
import sys
import socket

if socket.gethostname() == 'N551J':
    sys.stdin = open('a1.in')


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


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


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


def read_str():
    return input()


def solve():
    a, b, c, d, e, f = read_int_list()
    best_sugar = 0
    best_total = 100 * a
    for i in range(31):
        for j in range(31):
            water = i * 100 * a + j * 100 * b
            for k in range(3001):
                if water + k * c <= f and k * c * 100 <= water * e:
                    l1 = int((f - water - k * c) / d)
                    l2 = int((water * e // 100 - k * c) / d)
                    l = min(l1, l2)
                    if (i, j, k, l) != (0, 0, 0, 0):
                        sugar = k * c + l * d
                        total = water + sugar
                        density = sugar / total
                        best_density = best_sugar / best_total
                        if density > best_density:
                            best_sugar = sugar
                            best_total = total
    return best_total, best_sugar


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
print(*max(
  [[s/(s+w),s+w,s]
    for t in range(0,f+1,a*100)
    for w in range(t,f+1,b*100)
    if w>0
    for m in [min(f-w,w*e//100)+1]
    for u in range(0,m,c)
    for s in range(u,m,d)
  ])[1:])

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
q=[]
for t in range(0,f+1,a*100):
  for w in range(t,f+1,b*100):
    if w>0:
      m=min(f-w,w*e//100)+1
      for u in range(0,m,c):
        for s in range(u,m,d):
          v=s+w
          q.append([s/v,v,s])
print(*max(q)[1:])

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = -1
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        return max(max_con, mem[(water_sum, suger_sum)])
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        con = dps(mem, water_sum, suger_sum + s)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum + s
            max_con = con

    for w in water:
        if water_sum + suger_sum + w > F:
            continue
        con = dps(mem, water_sum + w, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum + w, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Solution (Python):

A, B, C, D, E, F = tuple(map(int, input().split()))
A, B = 100*A, 100*B
waters = set([a+b for b in range(0, F+1, B) for a in range(0, F+1, A) if a+b <= F])

res_water = min(A, B)
res_sugar = 0
max_ratio = 0

for w in sorted(waters):
    sugars = [c+d for c in range(0, int(w//100)*E+1, C)
                         for d in range(0, int(w//100)*E+1, D) 
                             if (c+d+w <= F) and (c+d <= int(w/100)*E)]
    sugar = max(sugars)
    
    if w+sugar==0:
        continue
    if 100*sugar / (w+sugar) > max_ratio:
        max_ratio = 100*sugar / (w+sugar)
        res_water = w
        res_sugar = sugar
print("{} {}".format(res_water+res_sugar, res_sugar))

Solution (Python):
A,B,C,D,E,F = list(map(int, input().split()))
maxdensity=0;
maxtotal=0;
maxsugar=0;

listwater = list()
for nA in range(30):
    for nB in range(15):
    	water = 100*(nA*A+nB*B)
    	if water == 0:
    		continue
    	if water <= F and (not water in listwater):
    		listwater.append(water)

listsugar = list()
for nC in range(3000):
    for nD in range(1500):
    	sugar = (nC*C+nD*D)
    	if sugar <= F/2 and (not sugar in listsugar):
    		listsugar.append(sugar)

listsugar.sort()
listwater.sort()

for i in range(len(listsugar)):
    for j in range(len(listwater)):
    	total = listsugar[i] + listwater[j]
    	sugar = listsugar[i]
    	if total == 0:
    		continue
    	if total <= F and sugar*100 <= E*(total-sugar):
    		if maxdensity*total < sugar:
    			maxdensity = float(sugar)/float(total)
    			maxtotal = total
    			maxsugar = sugar
    	
if maxtotal == 0:
	maxtotal = A*100
print(maxtotal,end=" ")
print(maxsugar)

Solution (Python):
def get_set(_max, a, b):
    ans = set()
    g = _max // a
    for h in range(g + 1):
        k = (_max - a * h) // b
        for l in range(k + 1):
            ans.add(a * h + b * l)
    ans.discard(0)
    return ans


a, b, c, d, e, f = map(int, input().split())
ab = get_set(f, a * 100, b * 100)
max_l, max_s, max_r = 0, 0, 0
for n in ab:
    o = min(f - n, n * e // 100)
    if o / (n + o) < max_r:
        continue
    tmp_max = max(get_set(o, c, d), default=0)
    tmp_rate = tmp_max / (n + tmp_max)
    if tmp_rate >= max_r:
        max_l = n + tmp_max
        max_s = tmp_max
        max_r = tmp_rate

print(max_l, max_s)

Solution (Python):
import math

m = [0,0,-1]
mem = [[-1 for i in range(3200)] for j in range(3200)]

def cal(a,b):
    try:
        return 100 * b / (a + b)
    except:
        return 0

def dfs(water,suger,p,nums):
    global m
    global mem
    
    if water+suger > nums[5]: pass
    elif mem[water][suger] == -1: 
        mem[water][suger] = cal(water,suger)
    else:
        return mem[water][suger]


    if water != 0 and ((suger / water > nums[4] / 100 ) or (water + suger > nums[5])):
        return p

    if m[2] < cal(water,suger):
        m = [water,suger,cal(water,suger)]

    ans = max(
            dfs(water + nums[0] * 100, suger, cal(water,suger), nums),
            dfs(water + nums[1] * 100, suger, cal(water,suger), nums),
            dfs(water, suger + nums[2], cal(water,suger),nums),
            dfs(water, suger + nums[3], cal(water,suger),nums)
            )
    return ans


nums = [int(x) for x in input().split()]
A,B = nums[0],nums[1]
dfs(nums[0]*100,0,0,nums)
dfs(nums[1]*100,0,0,nums)
print(str(m[0]+m[1]) + " " + str(m[1]))

Solution (Python):
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

class water_node():
    def is_meltable(self):
        if self.sugar <= self.water * self.meltable/100:
            return True
        return False
    def __init__(self, water, sugar, meltable):
        self.water = water
        self.sugar = sugar
        self.mass = water + sugar
        self.meltable = meltable
        self.is_all_melt = self.is_meltable()
        if self.sugar + self.water > 0:
            self.concentration = self.sugar * 100.0 /float(self.sugar + self.water)
        else:
            self.concentration = -1.0


    def __eq__(self,other):
        return (self.water  == other.water) and (self.sugar  == other.sugar)

    def __hash__(self):

        return hash (self.water + self.sugar* 10000)


def BFS(A, B, C, D, E, F):
    n = water_node(0, 0, E)
    done_set = set([n])
    node_list = deque([n])
    max_concentration_node = n
    while len(node_list) > 0:
        n = node_list.popleft()
        
        new_node_list = []
        new_node_list.append(water_node(n.water + A * 100, n.sugar, E))
        new_node_list.append(water_node(n.water + B * 100, n.sugar, E))
        new_node_list.append(water_node(n.water, n.sugar + C, E))
        new_node_list.append(water_node(n.water, n.sugar + D, E))
        for new_node in new_node_list:
            if new_node.mass <= F:
                if new_node not in done_set:
                    done_set.add(new_node)
                    node_list.append(new_node)
                    if new_node.is_all_melt == True and new_node.concentration > max_concentration_node.concentration:
                        max_concentration_node = new_node
    return max_concentration_node


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C, D, E, F] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3]), int(input_raw[4]), int(input_raw[5])]
    max_c = BFS(A, B, C, D, E, F)
    print int(max_c.mass), int(max_c.sugar)

if __name__ == '__main__':
    main()

Solution (Python):
import itertools

def solve():
    a, b, c, d, e, f = map(int, input().split())
    water_pair = []
    a_list = [a * i * 100 for i in range(f//(a * 100) + 1)]
    b_list = [b * i * 100 for i in range(f//(b * 100) + 1)]
    for elem in list(itertools.permutations(a_list + b_list, 2)):
        water_pair.append(elem[0] + elem[1])
    
    solt_max = int(f * ((100 * e) / (100 + e) / 100))
    water_pair = [i for i in set(water_pair) if f > i > 0]
    solt_pair = []
    c_list = [c * i for i in range(solt_max//c + 1)]
    d_list = [d * i for i in range(solt_max//b + 1)]
    for elem in list(itertools.permutations(c_list + d_list, 2)):
        solt_pair.append(elem[0] + elem[1])
    solt_pair = [i for i in set(solt_pair) if solt_max >= i]
    
    water_pair.sort()
    solt_pair.sort()
    max_pair = 0
    ans = [a * 100, 0]
    for water in water_pair:
        limit_solt = e * (water // 100)
        for solt in solt_pair:
            if solt > limit_solt:
                break
            if water + solt > f:
                break
            if (100 * solt) / (water + solt) > max_pair:
                max_pair = (100 * solt) / (water + solt)
                ans = [water + solt, solt]
    print(ans[0], ans[1])
    

if __name__=="__main__":
    solve()

Solution (Python):



A,B,C,D,E,F = map(int, input().split())
A *= 100
B *= 100
E = round(E/(100+E), 8)


def check(i, total, sugar):
	exp = (sugar + D*i) / (total + D*i)
	return total + D*i <= F and round(exp, 8) <= E
	

def binarySearch(small, big, total, sugar):
	mid = (big + small) // 2
	if big - small <= 1:
		if check(big, total, sugar): return big
		else:          return small
	else:
		if check(mid, total, sugar):
			return binarySearch(mid, big, total, sugar)
		else:
			return binarySearch(small, mid, total, sugar)

noudo = 0
ans = (0, 0)
for a in range(31):
	for b in range(31):
		for c in range(3001):
			water = a*A + b*B
			sugar = c * C
			total = water + sugar
			if not (a, b) == (0, 0):
				if total <= F and round(sugar / total, 8) <= E:
					d = binarySearch(0, 3000, total, sugar)
					tmp = (sugar + D*d) / (total + D*d)
					if round(tmp, 8) > noudo:
						noudo = round(tmp, 8)
						ans = (total+D*d, sugar+D*d)

if ans[0] == 0:
	print(A, 0)
else:
	print(ans[0], ans[1])

Solution (Python):

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

a,b,c,d,e,f=spaceinput()


smax=0
wmax=100*a
maxnoudo=0

for na in range(int(f/(100*a))+1):
    for nb in range(int(f/(100*b))+1):
        for nc in range(int(f/c)+2):
            for nd in range(int(f/d)+2):
                W=na*100*a+nb*100*b
                S=nc*c+nd*d


                if W+S>f:
                    break

                if W+S==0:
                    continue

                noudo=S/(W+S)
                
                
                if noudo>e/(100+e):
                    break

                
                if maxnoudo<noudo:
                    maxnoudo=noudo
                    smax=S
                    wmax=W
                    


print(smax+wmax,smax)

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

ans = [100 * a, 0]
for ka in range(f // (100 * a) + 1):
    for kb in range(f // (100 * b) + 1):
        for kc in range(f // c + 1):
            l = 0
            r = f // d + 1
            while 1 < r - l:
                m = (l + r) // 2
                sg = kc * c + m * d
                sw = 100 * ka * a + 100 * kb * b + sg
                if f < sw:
                    r = m
                    continue
                if (100 + e) * sg <= sw * e:
                    l = m
                else:
                    r = m
            kd = l
            sg = kc * c + kd * d
            sw = 100 * ka * a + 100 * kb * b + sg
            if sw <= f and (100 + e) * sg <= sw * e and ans[1] * sw < ans[0] * sg:
                ans = [sw, sg]
print(' '.join(map(str, ans)))