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):
a,b,c,d,e,f=map(int,input().split())
noudomax=0
weight=0
weightmax=100*a
sugarmax=0
i=0
while True:
    weight=a*100*i
    if weight>f:
        break
    j=0
    while True:
        if i==j==0:
            j+=1
            continue
        weight=a*100*i+b*100*j
        if weight>f:
            break
        k=0
        while True:
            weight=a*100*i+b*100*j+c*k
            if weight>f:
                break
            l=0
            while True:
                weight=a*100*i+b*100*j+c*k+d*l
                sugar=c*k+d*l
                if weight>f:
                    break
                noudo=100*sugar/weight
                if noudomax<noudo<=100*e/(e+100):
                    
                    weightmax=weight
                    sugarmax=sugar
                    noudomax=noudo
                l+=1
            k+=1
        j+=1
    i+=1

print(weightmax,sugarmax)

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

sw = 100 * A
sugar = 0
percent = 0
for k in range(F // (100 * A) + 1):
    for l in range(F // (100 * B) + 1):
        if k == 0 and l == 0:
            continue
        tmp = A * k + B * l
        if 100 * tmp > F:
            continue
        for i in range(tmp*E//C + 1):
            for j in range(tmp*E//D + 1):
                tmp2 = i * C + j * D
                if 100 * tmp + tmp2 > F:
                    continue
                if tmp2 > tmp * E:
                    continue
                t = 100 * tmp2 / (100 * tmp + tmp2)
                if t > percent:
                    percent = t
                    sw = 100 * tmp + tmp2
                    sugar = tmp2

print(sw, sugar)

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

ans, cont = [0]*2, 0

for i in range(f//100+1):
    if i%a == 0 or i%b == 0:
        water = i*100
        x = min(f-water, i*e)

        suger = 0

        for j in range(x//c+1):
            s3 = j*c
            suger = max(suger, s3+((x-s3)//d)*d)

        if water != 0:
            if cont <= (100*suger) / (water+suger):
                ans = [water, suger]
                cont = (100*suger) / (water+suger)

print(sum(ans), ans[1])

Solution (Python):

def ansloop(wcnt1, fcnt, n):
    wcnt1 *= n
    fcnt *= n
    tans = 0
    while wcnt1 >= 0:
        tmpans = wcnt1 * inlst[2]
        if tmpans <= cnt1 * n:
            tmp = tmpans
            for i in range(fcnt):
                tmp += inlst[3]
                if tmp <= cnt1 * n:
                    tmpans = tmp
                else:
                    break
            tans = max(tans, tmpans)
        wcnt1 -= 1
    return tans

inlst = list(map(int, input().split()))
ans1 = 0
cnt1 = inlst[0] * inlst[4]
if cnt1 + (inlst[0] * 100) > inlst[-1]:
    cnt1 = inlst[-1] - (inlst[0] * 100)
wcnt1 = (cnt1 // inlst[2] + 1)
fcnt = wcnt1
roopcnt = inlst[-1] // (cnt1 + 100 * inlst[0])

index = 1
for i in range(1, roopcnt + 1):
    tmp = ansloop(wcnt1, fcnt, i)
    if (100 * ans1) / (index * 100 * inlst[0] + ans1) < (100 * tmp) / (i * 100 * inlst[0] + tmp):
        ans1 = tmp
        index = i
print(100 * inlst[0] * index + ans1, ans1)

Solution (Python):
inlst = list(map(int, input().split()))
ans1 = 0
ans2 = 0
cnt1 = inlst[0] * inlst[4]
if cnt1 + (inlst[0] * 100) > inlst[-1]:
    cnt1 = inlst[-1] - (inlst[0] * 100)
wcnt1 = (cnt1 // inlst[2] + 1)
fcnt = wcnt1
roopcnt = inlst[-1] // (cnt1 + 100 * inlst[0])
def ansloop(wcnt1, fcnt, n):
    wcnt1 *= n
    fcnt *= n
    tans = 0
    while wcnt1 >= 0:
        tmpans = wcnt1 * inlst[2]
        if tmpans <= cnt1 * n:
            tmp = tmpans
            for i in range(fcnt):
                tmp += inlst[3]
                if tmp <= cnt1 * n:
                    tmpans = tmp
                else:
                    break
            tans = max(tans, tmpans)
        wcnt1 -= 1
    return tans
index = 1
for i in range(1, roopcnt + 1):
    tmp = ansloop(wcnt1, fcnt, i)
    if (100 * ans1) / (index * 100 * inlst[0] + ans1) < (100 * tmp) / (i * 100 * inlst[0] + tmp):
        ans1 = tmp
        index = i
print(100 * inlst[0] * index + ans1, ans1)

Solution (Python):

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

watars = []
import math
for i in range(int(math.floor(F/ (A*100)))+1):
    rest = F - A * 100 * i
    for j in range(int(math.floor(rest/ (B*100)))+1):
        watars.append(A*100*i + B*100*j)

salts = []
lim_salt = int(F * E // 100)
for i in range(int(math.floor(lim_salt/ C))+1):
    rest = lim_salt - C * i
    for j in range(int(math.floor(rest/ D))+1):
        salts.append(C*i + D*j)

watars = set(watars)
salts = set(salts)



max_ratio = 0
ans = [0, 0]
for watar in watars:
    if watar == 0:
        continue

    for salt in salts:
        amount = watar + salt
        ratio = salt / amount
        if amount <= F and salt <= watar * E / 100:
            if ratio > max_ratio:
                max_ratio = ratio
                ans = [watar, salt]

if max_ratio == 0:
    water = min([water for water in watars
                 if 0 < water <= F])
    print(water, 0)

else:
    print(sum(ans), ans[1])

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
Swater, sugar, percent = 100*A, 0, 0
for k in range(F//(100*A) + 1):
  for l in range(F//(100*B) + 1):
    if k == 0 and l == 0:
      continue
    M = k*A + l*B
    if 100 * M > F:
      continue
    for x in range(M*E//C + 1):
      for y in range(M*E//D + 1):
        S = C*x + D*y
        if 100*M+S > F:
          continue
        if S > M*E:
          continue
        t = 100*S / (100*M+S)
        if t > percent:
          percent = t
          Swater = 100*M+S
          sugar = S
print(Swater, sugar)

Solution (Python):
import sys


def solve(inp):
    (A, B, C, D, E, F) = map(int, inp.readline().split(' '))

    
    

    max_dense = 0
    result = (A * 100, 0)
    AB = sorted(list(set([a for a in range(0, int(F / 100) + 1, A)] + [b for b in range(0, int(F / 100) + 1, B)])))
    for water in AB:
        if water == 0:
            continue
        c = 0
        while water * 100 + c <= F and c <= water * E:
            d = 0
            while water * 100 + c + d <= F and c + d <= water * E:
                sugar = c + d
                total = water * 100 + sugar
                dense = 100 * sugar / total
                if dense > max_dense:
                    
                    max_dense = dense
                    result = (total, sugar)
                d += D
            c += C

    return "{} {}".format(result[0], result[1])


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
possible_x = set()
possible_y = set()
for i in range(32):
    for j in range(32):
        value = i*100*A+j*100*B
        if value <= F:
            possible_x.add(value)
for i in range(3001//C+10):
    for j in range(3001//D+10):
        value = C*i+D*j
        if value <= F:
            possible_y.add(value)
max_density = 0
max_water = 0
max_sugar = 0
for x in possible_x:
    for y in possible_y:
        if x+y > F:
            pass
        elif E*x/100 < y:
            pass
        else:
            if x+y == 0:
                pass
            elif (100*y)/(x+y) >= max_density:
                max_density = (100*y)/(x+y)
                max_water = x
                max_sugar = y
print(max_water+max_sugar,max_sugar)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()

  ans_n=-inf
  ans_pair=[0,0]
  xf=100*e/(100+e)
  for i in range(31):
    for j in range(31):
      for k in range(101):
        for l in range(101):
          xa=100*a*i+100*b*j
          xb=c*k+d*l

          
          if xa+xb>f:
            break

          if xa+xb==0:
            continue

          xc=100*xb/(xa+xb)
          if xc>xf:
            continue

          if ans_n<xc:
            ans_n=xc
            ans_pair=[xa+xb,xb]

  return str(ans_pair[0])+' '+str(ans_pair[1])


print(main())

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

for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if sugar*ans0>ans1*(water+sugar):
                    ans0 = water+sugar
                    ans1 = sugar

print(ans0, ans1)

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1

for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar

print(ans0, ans1)

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



W = set()
for a in range(0, F+1, A*100):
  for b in range(0, F+1, B*100):
    w = a+b
    if w==0 or w>F:
      continue
    W.add(w)
    

Suger = set()
for c in range(0, F+1, C):
  for d in range(0, F+1, D):
    s = c+d
    if s>F:
      continue
    Suger.add(s)
    
d_max = -1
ans = None
for w in W:
  for s in Suger:
    
    if w*E//100 < s or w+s > F:
      continue
    d = 100*s / (w+s) 
    if d > d_max:
      d_max = d
      ans = (w+s, s)
print(*ans)

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

water_list = []

def nearest_suger(suger1, suger2, rest_amount, water):
    max_sum = 0
    target = min(int(water * (e / 100)), rest_amount)
    for i in range((target//suger1)+1):
        for j in range((target//suger2)+1):
            sum = i * suger1 + j* suger2
            if sum > target:
                break
            if max_sum < sum:
                max_sum = sum
    return max_sum



for i in range(30):
    if 100*a*i <= f:
        water_list.append(100*a*i)
    if 100*b*i <= f:
        water_list.append(100*b*i)

water_list = set(water_list)
water_list = list(water_list)
water_list.sort()
water_list.pop(0)

max_percent = 0

for i in water_list:
    suger = nearest_suger(c, d, f-i, i)
    percent = suger / (i + suger)
    if percent == (e / 100):
        print(suger+i, suger)
        exit()
    elif percent > (e / 100):
        continue
    elif percent >= max_percent:
        max_percent = percent
        suger_ans = suger
        water_ans = i

print(water_ans + suger_ans, suger_ans)

Solution (Python):
a,b,c,d,e,f=map(int,input().split())
ans,con = [0]*2, 0
for i in range(f//100+1):
    
    if i%a==0 or i%b==0:
        w=i*100 
        x=min(f-w, i*e) 
        s=0
        
        
        for j in range(x//c+1):
            s3 = j*c
            
            s=max(s, s3+((x-s3)//d)*d)
            
        if w!=0: 
            if con<=(100*s)/(w+s):
                ans = [w,s]
                con = (100*s)/(w+s)
print(sum(ans), ans[1])

Solution (Python):
A, B, C, D, E, F = map(int, input().split())
dp = [-1]*(F+1)
dp[0] = 0

amount, ans = 1, 0
for i in range(1, F+1):
    if i < A*100:
        continue

    if i >= A*100 and dp[i-A*100] != -1:
        dp[i] = max(dp[i], dp[i-A*100])
    if i >= B*100 and dp[i-B*100] != -1:
        dp[i] = max(dp[i], dp[i-B*100])

    if i >= C and dp[i-C] != -1 and (dp[i-C]+C)/(i-C-dp[i-C]) <= E/100:
        dp[i] = max(dp[i], dp[i-C]+C)
    if i >= D and dp[i-D] != -1 and (dp[i-D]+D)/(i-D-dp[i-D]) <= E/100:
        dp[i] = max(dp[i], dp[i-D]+D)

    if ans/amount <= dp[i]/i:
        amount = i
        ans = dp[i]
print(amount, ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def can_make(num, a, b):
    while num >= 0:
        if num % a == 0 or num % b == 0:
            return True
        num -= a
    return False

def main():
    A, B, C, D, E, F = LI()
    if A > B:
        A, B = B, A
    if C > D:
        C, D = D, C
    max_perc = -1
    max_sugar = -1
    max_water = -1
    for unit in range(A, 31):
        water = unit * 100
        for sugar in range(min(F - water, unit*E)+1):
            
            
            
            if water + sugar > F:
                continue
            if 100*sugar/(water+sugar) > E:
                continue
            if can_make(sugar, C, D) and can_make(water, 100*A, 100*B):
                perc = sugar/(sugar + water)
                if perc >= max_perc:
                    max_perc = perc
                    max_sugar = sugar
                    max_water = water
    print(max_water + max_sugar, max_sugar)

main()

Solution (Python):
a, b, c, d, e, f=map(int, input().split())
def g(x, y):
  if y==0:
    return 0
  else:
    return x/y
  
maxnodo=g(e, 100+e)
a*=100
b*=100

candnodo=0
out=[a, 0]
q_max=f//b
for q in range(q_max, -1, -1):
  p_max=(f-b*q)//a
  for p in range(p_max, -1, -1):
    s_max=(f-(a*p+b*q))//d
    while s_max>0 and g(d*s_max, a*p+b*q+d*s_max)>maxnodo:
      s_max-=1
      
    for s in range(s_max, -1, -1):
      r=(f-(a*p+b*q+d*s))//c
      while r>0 and g(c*r+d*s, a*p+b*q+c*r+d*s)>maxnodo:
        r-=1
        
      if g(c*r+d*s, a*p+b*q+c*r+d*s)>candnodo:
        candnodo=g(c*r+d*s, a*p+b*q+c*r+d*s)
        out=[a*p+b*q+c*r+d*s, c*r+d*s]
        temp=[p, q, r, s]
print(*out)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,C,D,E,F = MI()
    A*=100
    B*=100
    water = []
    can = [False]*3001
    can[0] = True
    for i in range(3001-A):
        if can[i]:
            can[i+A] = True
    for i in range(3001-B):
        if can[i]:
            can[i+B] = True
    for i in range(1,3001):
        if can[i]:
            water.append(i)

    can = [False]*3001
    can[0] = True
    for i in range(3001-C):
        if can[i]:
            can[i+C] = True
    for i in range(3001-D):
        if can[i]:
            can[i+D] = True
    
    suger = []
    for i in range(1,3001):
        if can[i]:
            suger.append(i)
    
    
    

    ans = 0
    ans_water = A
    ans_suger = 0
    for w in water:
        want = min(F-w, (w//100)*E)
        idx = bisect_right(suger, want)
        if idx:
            s = suger[idx-1]
            if ans < s/(w+s):
                ans = s/(w+s)
                ans_water=w
                ans_suger=s
                
    print(ans_water+ans_suger,ans_suger)
if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,d,e,f = LI()
    ans = 0
    p = [100*a,0]
    n = 31
    for x in range(n):
        A = a*x
        for y in range(n):
            B = b*y
            s = A+B
            r = min(f-100*s,s*e)
            if r > 0:
                for z in range(r+1):
                    C = c*z
                    rest = r-C
                    if rest < 0:
                        break
                    w = rest//d
                    D = d*w
                    res = (C+D)/(100*s+C+D)
                    if ans < res:
                        ans = res
                        p[0] = 100*s+C+D
                        p[1] = C+D
    print(*p)
    return


if __name__ == "__main__":
    solve()

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

SIZE = 3001
W = [0] * SIZE
S = [0] * SIZE

W[A * 100] = 1
W[B * 100] = 1
S[0] = 1

for i in range(SIZE):
  if W[i]:
    if i + A * 100 < SIZE:
      W[i + A * 100] = 1
    if i + B * 100 < SIZE:
      W[i + B * 100] = 1
  if S[i]:
    if i + C < SIZE:
      S[i + C] = 1
    if i + D < SIZE:
      S[i + D] = 1
  
water = []
sugar = []
for i in range(SIZE):
  if W[i] and i <= F:
    water.append(i)
  if S[i] and i <= F:
    sugar.append(i)



max_p = -1
wss = (0, 0)
for w in water:
  for s in sugar:
    p = s / (s + w) * 100
    if w + s <= F and p <= E / (100 + E) * 100:
      if max_p < p:
        max_p = p
        wss = (w + s, s)
print(*wss)

Solution (Python):
from fractions import Fraction
from collections import deque
import math

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


waters = set()
waters.add(100*A)
if 200*B <= F:
    waters.add(200*B)
q = deque([100*A, 200*B])

while q:
    w = q.popleft()
    
    if w > F: continue
    for n in [100*A, 200*B]:
        if w + n <= F:
            waters.add(w + n)
            q.append(w + n)

waters = list(waters)
waters.sort()




max_conc = -1

total = -1
sugar = -1


for w in waters:
    
    limit = math.floor(w * Fraction(E,100))
    
    limit = min(limit, F - w)
    
    max_sugar = 0
    for i in range(limit // C + 1):
        tmp = C * i + ((limit - C*i) // D) * D
        
        max_sugar = max(max_sugar, tmp)
    if max_conc < Fraction(max_sugar, (w+max_sugar)):
        max_conc = Fraction(max_sugar, (w+max_sugar))
        total = w+max_sugar
        sugar = max_sugar

print(total, sugar)

Solution (Python):



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


waters = set()

for i in range(F//(100*A) + 1):
    for j in range((F-100*A*i)//(100*B) + 1):
        w = 100*A*i + 100*B*j
        if w != 0:
            waters.add(w)
waters = list(waters)
waters.sort()


sugars = set()

for i in range(F//C + 1):
    
    for j in range((F - C*i) // D + 1):
        s = i*C + j*D
  
        sugars.add(s)


sugars = list(sugars)
sugars.sort()


max_conc = -1

water = -1
sugar = -1




for w in waters:
    for s in sugars:

        
        if w+s > F: break
        
        if s*100 > w * E: break

        conc = s / (s+w)
        if conc > max_conc:
            max_conc = conc
            water = w
            sugar = s

print(sugar+water, sugar)

Solution (Python):



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


waters = set()

for i in range(F//(100*A) + 1):
    for j in range((F-100*A*i)//(100*B) + 1):
        w = 100*A*i + 100*B*j
        if w != 0:
            waters.add(w)
waters = list(waters)
waters.sort()


sugars = set()

for i in range(F//C + 1):
    
    for j in range((F - C*i) // D + 1):
        s = i*C + j*D
  
        sugars.add(s)


sugars = list(sugars)
sugars.sort()


max_conc = 0

total = 0
sugar = 0

best_w = best_s = best_r = -1
for water in sorted(waters):
    for sugar in sorted(sugars):
        if water + sugar > F: break
        if water*E < sugar*100: break
        rate = sugar / (water + sugar)
        if rate > best_r:
            best_r = rate
            best_w = water
            best_s = sugar
print(best_s+best_w, best_s)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100

limit = E / (100+E)


dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        
        if i+j > F:
            break
        
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = 0
mx = -1
for a in range(F+1):
    for b in range(F+1):
        if a == b == 0:
            continue
        if a+b > F:
            break
        if dp[a][b]:
            x = b / (a+b)
            
            if x > limit:
                continue
            
            if mx < x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100

limit = E / (100+E)


dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        
        if i+j > F:
            break
        
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = 0
mx = -1
for a in range(F+1):
    for b in range(F+1):
        if a == b == 0:
            continue
        if a+b > F:
            break
        if dp[a][b]:
            x = b / (a+b)
            
            if x > limit:
                continue
            
            if mx < x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100

limit = E / (100+E)


dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        
        if i+j > F:
            break
        
        if i+A <= F:
            dp[i+A][j] |= dp[i][j]
        if i+B <= F:
            dp[i+B][j] |= dp[i][j]
        if j+C <= F:
            dp[i][j+C] |= dp[i][j]
        if j+D <= F:
            dp[i][j+D] |= dp[i][j]

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            
            if x > limit:
                continue
            
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100

limit = E / (100+E)


dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        
        if i+j > F:
            break
        
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            
            if x > limit:
                continue
            
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100

limit = E / (100+E)


dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        
        if i+j > F:
            continue
        
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            
            if x > limit:
                continue
            
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)