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

import heapq
import math

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


n1, n2 = [F // (a * 100) for a in [A, B]]
ws = []
for i in range(n1+1):
    for j in range(n2+1):
        if i == 0 and j == 0: continue
        a1, a2 = i, j
        w = (a1 * A + a2 * B) * 100
        if w <= F:
            ws.append(w)
        else:
            break
ws = sorted(ws)
ss = []
for w in ws:
    remain = F - w
    max_sugar = w / 100.0 * E
    max_sugar = min(remain, max_sugar)

    x = 0
    max_tmp = -1
    while x * C < max_sugar:
        y = (max_sugar - (x * C) ) // D
        s = x*C + y*D
        if s > max_tmp:
            max_tmp = s
        x += 1
    ss.append([w, max_tmp])
max_tmp = None
for i, a in enumerate(ss):
    noudo = 1.0 * a[1] / (a[0] + a[1])
    if max_tmp is None or max_tmp[2] < noudo:
        max_tmp = [a[0], a[1], noudo]
print(int(max_tmp[0]+max_tmp[1]), int(max_tmp[1]))

Solution (Python):
from sys import stdin 
a,b,c,d,e,f = map(int,stdin.readline().split())
fir = [0] * (f+1)
sec = [0] * (f+1)

fir[0] = sec[0] = 1 
for i in xrange(f+1):
    nex = i + a*100 
    if nex<=f and fir[i]:
        fir[nex] = 1 
    nex = i + c 
    if  nex<=f and sec[i]:
        sec[nex] = 1 
    nex = i + b*100 
    if nex<=f and fir[i]:
        fir[nex] = 1 
    nex = i +  d 
    if  nex<=f and sec[i]:
        sec[nex] = 1 
valid = []
for i in xrange(1,f+1):
    for j in xrange(0,f+1):
        
        if fir[i] and sec[j]:
            if i +  j<=f:
                if e*i >= 100*j:
                    valid.append((i,j))
num = -1
den = 1*100
for y,x in valid:
    if x*den > y*num:
        num = x
        den = y
print num+den,num

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

water_dp = [True] + [False for _ in range(100)]
suger_dp = [True] + [False for _ in range(f + 100)]

for i in range(0, 31):
    water_dp[i+a] = water_dp[i+a] or water_dp[i]
    water_dp[i+b] = water_dp[i+b] or water_dp[i]

for i in range(0, f+1):
    suger_dp[i+c] = suger_dp[i+c] or suger_dp[i]
    suger_dp[i+d] = suger_dp[i+d] or suger_dp[i]

ans = (0, 0, 0)

for i in range(1, 31):
    if not water_dp[i]:
        continue
    suger = 0
    for j in range(0, f):
        if suger_dp[j] and i*100 + j <= f and j <= e * i:
            suger = j
    if suger * 100 / (i*100 + suger) > ans[2]:
        ans = (i, suger, suger * 100 / (i*100 + suger))

if ans[0] != 0:
    print(ans[0]*100 + ans[1], ans[1])
else:
    print(100 * a, 0)

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


from itertools import product
water = set()

for i,j in product(range(f//(a*100)+2),range(f//(100*b)+2)):
  n = a*i+b*j
  if n <= f:
    water.add(n)

water = sorted(water)

salt = set()

for i,j in product(range(f//c+2),range(f//d+2)):
  n = c*i+d*j
  if n <= f:
    salt.add(n)

salt = sorted(salt)

from bisect import bisect_left



bs,bw = 0,min(a,b)
for s in salt:
  w = s/e
  i = bisect_left(water,w)
  if i >= len(water):
    break
  w = water[i]
  if 100*w + s > f:
    break
  if bs*w < bw*s:
    bs,bw = s,w

print(bs+100*bw,bs)

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

ans_water = None
ans_sugar = None

for a in xrange(0, int(F/(100*A))+1):
  waterA = 100 * A * a
  for b in xrange(0, int((F-waterA)/(100*B))+1):
    water = waterA + 100 * B * b
    for c in xrange(0, int((F-water)/C)+1):
      sugarC = C * c
      for d in xrange(0, int((F-water-sugarC)/D)+1):
        sugar = sugarC + D * d
        if sugar * (100 + E) <= (water + sugar) * E:
          if (not ans_water) or (not ans_sugar) or ans_sugar * (water + sugar) < (ans_water + ans_sugar) * sugar:
            ans_water = water
            ans_sugar = sugar

print (ans_water + ans_sugar), ans_sugar

Solution (Python):

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


def read():
    A, B, C, D, E, F = ILI()
    return A, B, C, D, E, F


def solve(A, B, C, D, E, F):
    s_wat = set()
    for a in range(F // (100 * A) + 1):
        now_wat = a * 100 * A
        while now_wat <= F:
            if now_wat != 0:
                s_wat.add(now_wat)
            now_wat += 100 * B
    par = -1
    ans_sug_wat = 0
    ans_sug = 0
    for wat in sorted(list(s_wat)):
        sug_limit = min(((wat // 100) * E), F - wat)
        for c in range(sug_limit // C + 1):
            now_sug = c * C
            now_sug += ((sug_limit - now_sug) // D) * D
            now_par = 100 * (now_sug / (now_sug + wat))
            if now_par > par:
                ans_sug_wat = now_sug + wat
                ans_sug = now_sug
                par = now_par
    ans = "{} {}".format(ans_sug_wat, ans_sug)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):

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

A_limit = F // (100*A)

max_density = 0.0
max_suger = 0
max_total = 0

for a in range(A_limit + 1):
    B_limit = (F-100*A*a) // (100*B)
    for b in range(B_limit + 1):
        water = 100*A*a + 100*B*b
        
        suger_limit = min(water*E // 100, F - water)
        
        suger_ = 0
        for c in range(suger_limit // C + 1):
            d = (suger_limit - C*c) // D
            suger = C*c + D*d
            suger_ = max(suger, suger_)
        
        if (suger_ + water) > 0:
            if suger_ / (suger_ + water) >= max_density:
                max_density = suger_ / (suger_ + water)
                max_suger = suger_
                max_total = suger_ + water

print(str(max_total)+" "+str(max_suger))

Solution (Python):
import sys
sys.setrecursionlimit(100000)
a, b, c, d, e, f = map(int, input().split())
def dfs(g, a, b, can, base=100):
    if not base*g <= f:
        return
    if g in can:
        return
    can[g] = 1
    dfs(g + a, a, b, can, base)
    dfs(g + b, a, b, can, base)
can1 = {}
dfs(0, a, b, can1)
can2 = {}
dfs(0, c, d, can2, 1)

ans = (0, 0, 0)
for g in can1:
    if g == 0:
        continue
    rest = f - 100*g
    result = max([0]+[h for h in can2 if h <= min(rest, e*g)])
    ans = max(ans, (result / (100.*g + result), 100*g+result, result))
print(*ans[1:])

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

w  = [False for i in range(f+1)]
s  = [False for i in range(f+1)]
w[0] = True
s[0] = True
for i in range(f+1):
    if not w[i]:
        continue
    if i+(100*a) <= f:
        w[i+(100*a)] = True
    if i+(100*b) <= f:
        w[i+(100*b)] = True
for i in range(f+1):
    if not s[i]:
        continue
    if i+c <= f//2:
        s[i+c] = True
    
    if i+d <= f//2:
        s[i+d] = True

ww = [i for i in range(1, f+1) if w[i]]
ss = [i for i in range(1, f+1) if s[i]]

max_w = a*100
max_s = 0
max_r = 0
for w in ww:
    for s in ss:
        if s <= e*w//100 and s+w <= f and s/(w+s)>max_r:
            max_r = s/(w+s)
            max_s = s
            max_w = w
print(max_w+max_s, max_s)

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

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

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 main():
    a,b,c,d,e,f = LI()
    f += 1
    a *= 100
    b *= 100
    m = [0] * f
    s = [0] * f
    m[0] = 1
    s[0] = 1
    for i in range(f-a):
        if m[i] == 1:
            m[i+a] = 1
    for i in range(f-b):
        if m[i] == 1:
            m[i+b] = 1

    for i in range(f-c):
        if s[i] == 1:
            s[i+c] = 1
    for i in range(f-d):
        if s[i] == 1:
            s[i+d] = 1

    mr = 0
    r = [a,0]
    e = e / (100+e)
    for i in range(0,f):
        if m[i] == 0:
            continue
        for j in range(1,f-i):
            if i+j >= f:
                break
            if s[j] == 0:
                continue
            k = j / (i+j)
            if k > e:
                break
            if k > mr:
                mr = k
                r = [i+j, j]

    return ' '.join(map(str,r))


print(main())

Solution (Python):
A,B,C,D,E,F = map(int,input().split())
possibleWater = {0}
for i in range(F//(100*A)):
    copy = set(possibleWater)
    for x in copy:
        possibleWater.add(x+100*A)
for i in range(F//(100*B)):
    copy = set(possibleWater)
    for x in copy:
        possibleWater.add(x+100*B)
possibleSugar = {0}
for i in range(F//C):
    copy = set(possibleSugar)
    for x in copy:
        possibleSugar.add(x+C)
for i in range(F//D):
    copy = set(possibleSugar)
    for x in copy:
        possibleSugar.add(x+D)

bestWater = -1
bestSugar = -1
bestDensity = -1
possibleWater.remove(0)
for w in possibleWater:
    for s in possibleSugar:
        
        if w/100 * E < s:
            
            continue
        if w+s>F:
            
            continue
        density = 100*s/(w+s)
        if density>bestDensity:
            bestDensity = density
            bestWater = w
            bestSugar = s

print(bestWater+bestSugar,bestSugar)