Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Snuke will make sugar water with the highest possible density.

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

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

Constraints

1 \leq A < B \leq 30

1 \leq C < D \leq 30

1 \leq E \leq 100

100A \leq F \leq 3 000

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

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

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

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10

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

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

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

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

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

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

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934



Sample input:
1 2 10 20 15 200


Sample output:
110 10

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
water = []
suger = []
import math
for p in range(0, math.floor(f / (100 * a)) + 1) :
    for q in range(0, math.floor(f / (b * 100)) + 1) :
        if p * 100 * a + q * 100 * b <= f:
            water += [p * 100 * a + q * 100 * b]
for p in range(0, math.floor(f / c) + 1) :
    for q in range(0, math.floor(f / d) + 1) :
        if  p * c + q * d <= f :
            suger += [p * c + q * d]
water = sorted(list(set(water)))[1:]
suger = sorted(list(set(suger)))
c = []
for w in water :
    for s in suger :
        if w + s <= f:    
            if s / w <= e /100 :
                c += [[w, s, w + s]]
c = sorted(c, key = lambda x : x[1] / x[2],reverse=True)
print(c[0][2], c[0][1])

Submission status: Accepted

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

max_sugar = 0
max_water = 100 * A
max_conc = 0.0
A_limit = F // (100 * A)
for i in range(A_limit + 1):
    B_limit = (F - 100 * A * i) // (100 * B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        water_rate = A * i + B * j
        sugar_limit = min(E * water_rate, F - 100 * water_rate)

        sugar = 0
        for c in range(sugar_limit // C + 1):
            d = (sugar_limit - c * C) // D
            temp_sugar = c * C + d * D
            sugar = max(sugar, temp_sugar)
        temp_cons = sugar / (sugar + 100 * water_rate)
        if temp_cons > max_conc:
            max_conc = temp_cons
            max_water = 100 * water_rate
            max_sugar = sugar
print("{} {}".format(max_water + max_sugar, max_sugar))

Submission status: Accepted

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

max_sugar = 0
max_water = 100 * A
max_conc = 0.0
A_limit = F // (100 * A)
for i in range(A_limit + 1):
    B_limit = (F - 100 * A * i) // (100 * B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A * i + B * j), F - 100 * (A * i + B * j))

        sugar = 0
        for c in range(sugar_limit // C + 1):
            d = (sugar_limit - c * C) // D
            temp_sugar = c * C + d * D
            sugar = max(sugar, temp_sugar)
        temp_cons = sugar / (sugar + 100 * (A * i + B * j))
        if temp_cons > max_conc:
            max_conc = temp_cons
            max_water = 100 * (A * i + B * j)
            max_sugar = sugar
print("{} {}".format(max_water + max_sugar, max_sugar))

Submission status: Accepted

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

ans = [0, 0]
max_conc = -1
for a in range(F // 100 + 1):
    left = F - 100 * a * A
    for b in range(left // 100 + 1):
        w = 100 * a * A + 100 * b * B

        s_max = min(F - w, w * E // 100)
        if s_max >= 0:
            for c in range(s_max // C + 1):
                d = (s_max - c * C) // D

                if d >= 0:
                    # suger
                    s = c * C + d * D
                    if s + w > 0:
                        conc = s / (s + w)
                        if conc > max_conc:
                            ans = [s, w]
                            max_conc = conc


print(str(ans[0] + ans[1]) + ' ' + str(ans[0]))

Submission status: Accepted

Solution code:
# 何でこのプログラムで通らないか分からん
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    a, b, c, d, e, f = MI()
    max_sw = a*100
    max_s = 0
    for an in range(f // (100 * a) + 1):
        for bn in range((f - 100 * a * an) // (100 * b) + 1):
            w = a * an + b * bn
            if w == 0: continue
            if 100 * w > f: break
            for cn in range(f):
                dn = (min(w * e, f - 100 * w) - c * cn) // d
                if dn < 0: break
                # print(an,bn,cn,dn)
                s = c * cn + d * dn
                if s * max_sw > max_s * (s + w * 100):
                    max_sw = s + 100 * w
                    max_s = s
    print(max_sw, max_s)

main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

def main():
    ans_sw=100*a
    ans_s=0
    for an in range(f+1):
        if a*an*100>f:break
        for bn in range(f+1):
            w=an*a+bn*b
            if w*100>f:break
            lim=min(w*e,f-w*100)
            for cn in range(f+1):
                dn=(lim-c*cn)//d
                if dn<0:break
                s=c*cn+d*dn
                if s*ans_sw>ans_s*(s+100*w):
                    ans_sw=s+100*w
                    ans_s=s
    print(ans_sw,ans_s)

main()

Submission status: Accepted

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

Water = []
for i in range(0, f // (a * 100) + 1):
  for j in range(0, f // (b * 100) + 1):
    if (i * a + j * b) * 100 <= f:
      Water.append((i * a + j * b) * 100)
#print(list(set(Water)))

import math
Solt = []
for i in range(0, math.ceil((f * e / 100) / c) + 1):
  for j in range(0, math.ceil((f * e / 100) / d) + 1):
    if i * c + j * d <= (f * e / 100):
      Solt.append(i * c + j * d)
#print(list(set(Solt)))

max_cnc = 0
champ_w = 0
champ_s = 0
from itertools import product 
for pair in product(list(set(Water[1:])), list(set(Solt))):
#  print(pair[0], pair[1])
  vol = pair[0] + pair[1]
  if vol > f:
    continue
  if pair[1] * 100 / pair[0] > e:
    continue
  cnc = pair[1] * 100 / (pair[0] + pair[1])
#  print(pair[0], pair[1], cnc)
  max_cnc = max(cnc, max_cnc)
  if cnc == max_cnc:
    champ_w = pair[0]
    champ_s = pair[1]
print(champ_w + champ_s, champ_s)

Submission status: Accepted

Solution code:
import sys
import math
a, b, c, d, e, f = [int(i) for i in sys.stdin.readline().split()]
max_sugar = 0
max_sum = min(a, b) * 100
max_noudo = 0
for _a in range(f // a):
    max_b = math.floor((f - _a * a * 100) / b) + 1
    for _b in range(max_b):
        water = (_a * a + _b * b) * 100
        max_c = math.floor(min(f - water, (_a * a + b * _b) * e) / c) + 1
        for _c in range(max_c):
            _d = max(0, min((f - water - _c * c) // d, ((_a * a + _b * b) * e - _c * c) // d))
            if _c + _d == 0:
                continue
            if (_a * a + _b * b) * 100 + _c * c + _d * d > f:
                continue
            noudo = (c * _c + d * _d) / ((_a*a + _b*b) * 100)
            if noudo > e / 100:
                continue
            elif noudo > max_noudo:
                max_sugar = _c * c + _d * d
                max_sum = (_a*a + _b*b) * 100 + max_sugar
                max_noudo = noudo
print(max_sum, max_sugar)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b,c,d,e,f=map(int,input().split())
    Water=set()
    Sugar=set()
    for i in range(30):
        for j in range(30):
            w=100*i*a+100*j*b
            if(w>f): break
            Water.add(w)
    Water.remove(0)

    for i in range(b):
        for j in range(1500):
            s=i*c+j*d
            if(s*(100+e)>f*e): break
            Sugar.add(s)

    from itertools import product
    SW=list(product(Water,Sugar))
    SW.sort(lambda x:x[1]/(x[0]+x[1]), reverse=1)
    for w,s in SW:
        if(s+w<=f and s*(100+e)<=e*(s+w)):
            print(s+w,s)
            return
resolve()

Submission status: Accepted

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

CONCENT_LIMIT = E/(100+E)
max_concent = 0
water_at_max = 0
sugar_at_max = 0
for num_b in range(F//(100*B)+1):
    #print("B: ", num_b)
    rest_cap = F - num_b*B*100
    if rest_cap < 0:
        break
        
    for num_a in range(rest_cap//(100*A)+1):
        #print("  A: ", num_a)
        rest_cap_ = rest_cap - num_a*A*100
        water = num_b*B*100+num_a*A*100
        if rest_cap_ <= 0:
            break
        if water == 0:
            continue
            
        for num_d in range(rest_cap_//D+1):
            #print("    D: ", num_d)
            rest_cap__ = rest_cap_ - num_d*D
            if rest_cap__ < 0:
                break
                
            for num_c in range(rest_cap__//C+1):
                #print("      C: ", num_c)
                sugar = num_d*D+num_c*C
                if water+sugar > F:
                    break
                concent = sugar / (water+sugar)

                if (concent <= CONCENT_LIMIT) & (concent >= max_concent):
                    max_concent = concent
                    sugar_at_max = sugar
                    water_at_max = water
                
print(water_at_max+sugar_at_max, end=" ")
print(sugar_at_max)

Submission status: Accepted

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

liw = [0]*31
liw[0] = 1
for i in range(30):
  if liw[i] == 1:
    if i+a <= 30:
      liw[i+a] = 1
    if i+b <= 30:
      liw[i+b] = 1

liww = []
for i in range(1,31):
  if liw[i] == 1:
    liww.append(i)

maxs = 30*e+1
lis = [0]*maxs
lis[0] = 1
for i in range(maxs-1):
  if lis[i] == 1:
    if i+c <= maxs-1:
      lis[i+c] = 1
    if i+d <= maxs-1:
      lis[i+d] = 1
liss = []
for i in range(1,maxs):
  if lis[i] == 1:
    liss.append(i)

ans = [0,0,0]
#print(liss)
for i in liww:
  if 100*i > f:
    break
  maxsug = min(f-100*i,i*e)
  #print(maxsug)
  if bi.bisect_right(liss,maxsug) == 0:
    tmpsug = 0
  else:
    #print(bi.bisect_right(liss,maxsug))
    tmpsug = liss[bi.bisect_right(liss,maxsug)-1]
  #print(tmpsug)
  if ans[2] <= tmpsug/(tmpsug+100*i):
    ans[0] = tmpsug+100*i
    ans[1] = tmpsug
    ans[2] = tmpsug/(tmpsug+100*i)
print("{} {}".format(ans[0],ans[1]))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
a,b,c,d,e,f=map(int,input().split())
L=[]
M=[]
from functools import lru_cache
@lru_cache(maxsize=1000)
def dfs(s,w):
    if s+w>f or s>f*e/(100+e):
        return
    x=(100*s)/(s+w)
    m=(100*e)/(e+100)
    if x==m:
        L.append([x,s+w,s])
        return
    elif x>m:
        dfs(s,w+100*a)
        dfs(s,w+100*b)
    else:
        L.append([x,s+w,s])
        dfs(s+c,w)
        dfs(s+d,w)
dfs(0,100*a)
dfs(0,100*b)
LS=sorted(L,key=lambda x:x[0],reverse=True)
print(LS[0][1],LS[0][2])

Submission status: Accepted

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

W=[]
for i in range(30):
  for j in range(30):
    if (i*A+j*B)*100<=F:
      W.append((i*A+j*B)*100)
W=sorted(set(W))

S=[]
for i in range(F):
  for j in range(F):
    if i*C+j*D<=F:
      S.append(i*C+j*D)
S=sorted(set(S))

nou=0
for w in W:
  for s in S:
    if w+s<=F:
      if E*w//100>=s:
        if w!=0 or s!=0:
          if nou<=s/(w+s):
            nou=s/(w+s)
            ans=[w+s,s]
        
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
W = []
for i in range(F + 1):
  for j in range(F + 1):
    if A * i * 100 + B * j * 100 < F:
      W.append(A * i * 100 + B * j * 100)
    else:
      break

S = []
for i in range(F + 1):
  for j in range(F + 1):
    if C * i + D * j < F:
      S.append(C * i + D * j)
    else:
      break

# print(S)
# print(W)
      
ans = 0
ans1, ans2 = 0, 0
for i in S:
  for j in W:
    if i + j > 0 and i + j <= F and j * E >= 100 * i:
      if i / (i + j) >= ans:
        ans1, ans2 = i, j
        ans = i / (i + j)

print(ans1 + ans2, ans1)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
X = [1] + [0] * F
Y = [1] + [0] * F
for i in range(1, F+1):
    if i >= A*100 and X[i-A*100]: X[i] = 1
    if i >= B*100 and X[i-B*100]: X[i] = 1
    if i >= C and Y[i-C]: Y[i] = 1
    if i >= D and Y[i-D]: Y[i] = 1

ans = (0, 0)
ratio = -1
for i in range(100, F+1, 100):
    for j in range(F+1):
        if X[i] and Y[j]:
            if j <= i // 100 * E and i + j <= F:
                if j / i > ratio:
                    ans = (i+j, j)
                    ratio = j / i
print(*ans)

Submission status: Accepted

Solution code:
def examC():
    A, B, C, D, E, F = LI()
    water =set()
    for i in range(30):
        for j in range(30):
            if 100 * (i*A+j*B) > F or (i==0 and j==0):
                continue
            water.add(100 * (A*i+B*j))
    sugar = set()
    for i in water:
        j = 0
        while(True):
            if (j * C) * 100 > i * E or i+(j*C)>F:
                break
            k = 0
            while(True):
                if (j*C+k*D)*100>i*E or i+(j*C+k*D)>F:
                    j +=1
                    break
                sugar.add((i+j*C+k*D,j*C+k*D))
                k +=1
    ans = [0,0]; cur = float(-1)
    for i in sugar:
        if cur<i[1]/i[0]:
            ans = [i[0],i[1]]
            cur = i[1]/i[0]
    print(" ".join(map(str,ans)))
#    print(sugar)


import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

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

sugar = []
water = []

for i in range(31):
    for j in range(31):
        x = 100*A*i+100*B*j
        if x != 0 and x <= F:
            water.append(x)
        
n = int(F/(100+E)*E)

for k in range(n):
    for l in range(n):
        y = C*k+D*l
        if y != 0:    
            sugar.append(y)

ans_water_sugar = 100*A
ans_sugar = 0
conce = 0 

for s in list(set(sugar)):
    for w in water:
        if w+s <= F:
            if s/w <= E/100:
                if conce < s/w:
                    conce = s/w
                    ans_water_sugar = s+w
                    ans_sugar = s

print(ans_water_sugar, ans_sugar)

Submission status: Accepted

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

L = []
for i in range(f//a//100+1):
    for j in range(f//b//100+1):
        if 0 < 100*(a*i+b*j) < f and 100*(a*i+b*j) not in L:
            L.append(100*(a*i+b*j))
            
W = 1
S = 0
for w in L:
    s = 0
    for j in range(w//c+1):
        for k in range(w//d+1):
            if (c*j+d*k)*100 <= e*w and c*j+d*k+w <= f:
                s = max(s, c*j+d*k)
    if S*(w+s) < s*(W+S):
        S = s
        W = w
    
if W >= 100:
    print(S+W, S)
else:
    print(100*a, 0)

Submission status: Accepted

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

X = []
Y = []
for i in range(F):
    for j in range(F):
        x = A * i + B * j
        if x * 100 <= F:
            X.append(x)
        y = C * i + D * j
        if y <= F:
            Y.append(y)
m = -1
ans = []
for x in X:
    if x == 0: continue
    for y in Y:
        if x * 100 + y <= F and x * E >= y:
            if m < y / (x + y):
                m = y / (x + y)
                ans = (x * 100 + y, y)

print(*ans)

Submission status: Accepted

Solution code:
import math
a, b, c, d, e, f = [int(x) for x in input().split()]
threshold = e / (100 + e) * 100
max_concent = 0
max_total = 0
max_suger = 0
max_suger_try = int(threshold/100*f//c)
for i in range(31):
    for j in range(31):
        for k in range(max_suger_try):
            for l in range(max_suger_try):
                water = a * i * 100 + b * j * 100
                suger = c * k + d * l   
                if water == 0:
                    break
                concentration = suger / (water + suger) * 100
                if (water + suger > f or concentration > threshold) :
                    break
                else:
                    if concentration > max_concent:
                        max_concent = concentration
                        max_total = water + suger
                        max_suger = suger
if max_total == 0:
    max_total = a * 100
print("{} {}".format(max_total, max_suger))

Submission status: Accepted

Solution code:
num = list(map(int, input().split()))

A = num[0]
B = num[1]
C = num[2]
D = num[3]
E = num[4]
F = num[5]

watA_max = F // (100 * A)
sugar = 0
water = 0
beaker = F
ans = []
for i in range(1, watA_max+1):
    water = 100 * A * i
    beaker = F - (100 * A * i)
    watB_max = beaker // (100 * B)
    for j in range(watB_max+1):
        water = 100 * (A * i + B * j)
        beaker = F - (100 * (A * i + B * j))
        sugC_max = beaker // C
        for k in range(sugC_max+1):
            sugar = C * k
            beaker = F - (100 * (A * i + B * j)) - C * k
            if sugar * 100 > water * E:
                break
            sugD_max = beaker // D
            for l in range(sugD_max+1):
                sugar = C * k + D * l
                beaker = F - (100 * (A * i + B * j)) - C * k - D * l
                if sugar * 100 > water * E:
                    break
                if ans == [] or sugar / water >= ans[-1][-1]:
                    ans.append([sugar + water, sugar, sugar / water])
                
print(ans[-1][0], ans[-1][1])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
w=set([])
for i in range(31):
    for j in range(31):
        x=a*i*100+b*j*100
        if 0<x<=f:
            w.add(x)
s=set([])
for i in range(3001):
    for j in range(3001):
        y=c*i+d*j
        if y<=f:
            s.add(y)
tmpn=-1
ans=[0,0]
for i in w:
    for j in s:
        if i+j<=f and i//100*e>=j:
            if tmpn<j/(1.0*(i+j)):
                tmpn=j/(1.0*(i+j))
                ans=[i+j,j]
print(*ans)

Submission status: Accepted

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

for i in range(1, F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        a = 100 * A * i + 100 * B * j
        if a > F:
            break
        for k in range((F - a) // C + 1):
            for l in range((F - a - C * k) // D + 1):
                b = k * C + l * D
                concentration = 100 * b / (a + b)
                if (A * i + B * j) * E >= b and a + b <= F:
                    if concentration > c:
                        c = concentration
                        ans = [a + b, b]
                else:
                    break

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

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
ansx,ansy = 1, 0
for ai in range(F//(100*A)+1):
  for bi in range(F//(100*B)+1):
    if ai ==0 and bi ==0: continue
    s = 0
    for ci in range((F-ai*100*A + bi*100*B)//C +1):
      for di in range((F-ai*100*A + bi*100*B)//D +1):
        s = ci*C + di*D
        if s <=(ai*A + bi*B)*E and s + ai*100*A + bi*100*B <= F:
          if 100*ansy/(ansx+ansy) <= 100*s/(s + ai*100*A + bi*100*B):
            ansx = ai*100*A + bi*100*B
            ansy = s
      
print(ansx+ansy, ansy)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
X=F//100
w,s=100*A,0
for x in range(X,0,-1):
    a,b=0,0
    while A*a<=x:
        b=(x-A*a)%B
        if b==0:
            break
        a+=1
    if b==0:
        b=(x-A*a)//B
        maxs=min(E*x,F-100*(A*a+B*b))
        c,d=0,0
        cc=0
        while C*cc<=maxs:
            dd=(maxs-C*cc)//D
            if C*cc+D*dd>C*c+D*d:
                c,d=cc,dd
            cc+=1
        if s/w<(C*c+D*d)/(100*(A*a+B*b)+C*c+D*d):
            s,w=C*c+D*d,100*(A*a+B*b)+C*c+D*d
print(w,s)

Submission status: Accepted

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

dp = [[False for i in range(3001)] for j in range(2)]
for i in range(3001):
    if i % C == 0:
        dp[0][i] = True
for i in range(3001):
    if i % D == 0 or dp[0][i] or (i - D >= 0 and dp[1][i - D]):
        dp[1][i] = True
    
ans_sugar = 0
ans_total = 0
for i in range(31):
    for j in range(31):
        water = i * 100 * A + j * 100 * B
        if water > F:
            break
        for k in range(3000, -1, -1):
            sugar = k
            total = water + sugar
            if (water // 100) * E < sugar or F < total or not dp[1][k]:
                continue
            else:
                if (ans_sugar == 0 and ans_total == 0) or sugar * ans_total > total * ans_sugar:
                    ans_sugar = sugar
                    ans_total = total
                    break
print(ans_total, ans_sugar)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
a*=100
b*=100
x=set()
for i in range(0,f+1,a):
    for j in range(0,f+1,b):
        if 0<(i+j)<=f:
            x.add(i+j)
y=set()
for i in range(0,f+1,c):
    for j in range(0,f+1,d):
        if 0<(i+j)<=f:
            y.add(i+j)

ans=[]
for n in x:
    for m in y:
        if n+m>f:
            continue
        if n*e<m*100:
            continue
        ans.append([n+m,m,m/n])
if not ans:
    print(a,0)
    exit()
ans.sort(key=lambda x:x[2], reverse=True)

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

Submission status: Accepted

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

water = set()
suger = set()

for i in range(f+1):
    for j in range(f+1):
        x = 100 * (a * i + b * j)
        if x <= f:
            water.add(x)

for i in range(f+1):
    for j in range(f+1):
        y = c * i + d * j
        if y <= f:
            suger.add(y)


conc = 0
S = 0
W = 0

for s in suger:
    for w in water:
        if s + w > f:
            continue
        if s + w == 0:
            continue
        if  s > (w / 100)*e:
            continue
        temp = 100 * s / (s + w)
        if temp >= conc:
            conc = temp
            W = w
            S = s

print(S + W, S)

Submission status: Accepted

Solution code:
from bisect import bisect
a,b,c,d,e,f=map(int,input().split())
g=f//100
lst=[0]*(g+1)
i=0
for i in range(31):
    for j in range(31):
        h=a*i+b*j
        if h<=g:
            lst[h]=1
data=[]
for i in range(g*e//c):
    for j in range(g*e//d):
        data.append(c*i+d*j)
if not data:
    data=[0]
data.sort()
ans=-1
z=[]
for i in range(1,g+1):
    if lst[i]==0:
        continue
    k=100*i
    m=bisect(data,i*e)
    if m==0:
        continue
    o=data[m-1]
    if k+o<=f:
        if ans<=100*o/(k+o):
            z=[k+o,o]
            ans=100*o/(k+o)
    else:
        m=bisect(data,f-k)
        o=data[m-1]
        if ans<=100*o/(k+o):
            z=[k+o,o]
            ans=100*o/(k+o)
print(*z)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
s, w = (0, 100 * A)
water_list = [False] * (6000)
sugar_list = [False] * (6000)
water_list[0] = True
sugar_list[0] = True
for i in range(F):
    water_list[i + A * 100] = water_list[i + A * 100] or water_list[i]
    water_list[i + B * 100] = water_list[i + B * 100] or water_list[i]
    sugar_list[i + C] = sugar_list[i + C] or sugar_list[i]
    sugar_list[i + D] = sugar_list[i + D] or sugar_list[i]

for wi in range(0, F + 1, 100):
    for si in range(F + 1):
        if si * 100 <= wi * E and si + wi <= F and water_list[wi] and sugar_list[si]:
            if si * (s + w) > s * (si + wi):
                s, w = (si, wi)
print('{} {}'.format(s + w, s))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
s, w = (0, 0)
water_list = [False] * (6000)
sugar_list = [False] * (6000)
water_list[0] = True
sugar_list[0] = True
for i in range(F):
    water_list[i + A * 100] = water_list[i + A * 100] or water_list[i]
    water_list[i + B * 100] = water_list[i + B * 100] or water_list[i]
    sugar_list[i + C] = sugar_list[i + C] or sugar_list[i]
    sugar_list[i + D] = sugar_list[i + D] or sugar_list[i]

for wi in range(0, F + 1, 100):
    for si in range(F + 1):
        if si * 100 <= wi * E and si + wi <= F and water_list[wi] and sugar_list[si]:
            if (si * (s + w) >= s * (si + wi)) or (s == 0 and si > 0):
                s, w = (si, wi)
print('{} {}'.format(s + w, s))

Submission status: Accepted

Solution code:
from sys import stdin
import math
A, B, C, D, E, F = [int(x) for x in stdin.readline().rstrip().split()]

water = set()
for i in range(0, F//(100*A)+1):
    for j in range(0, F//(100*B)+1):
        water.add(A*i*100+B*j*100)

sugar = set()
capa = math.ceil(F/100)*E
for k in range(0, capa//C+1):
    for l in range(0, capa//D+1):
        sugar.add(C*k+D*l)

W = 0
S = 0
conc = 0
#print(water)
#print(sugar)
for w in water:
    for s in sugar:
        if w + s > F:
            continue
        if w+s == 0:
            continue
        if s > (w / 100)*E:
            continue
        tmp = (100*s)/(w+s)
        if tmp >= conc:
            conc = tmp
            W = w
            S = s
        #print(conc,w,s)
print(W+S,S)

Submission status: Accepted

Solution code:
from sys import stdin
import math
A, B, C, D, E, F = [int(x) for x in stdin.readline().rstrip().split()]

water = set()
for i in range(0, F//(100*A)+1):
    for j in range(0, F//(100*B)+1):
        water.add(A*i*100+B*j*100)

sugar = set()
capa = math.ceil(F/100)*E
for k in range(0, capa//C+1):
    for l in range(0, capa//D+1):
        sugar.add(C*k+D*l)

W = 0
S = 0
conc = 0
#print(water)
#print(sugar)
for w in water:
    for s in sugar:
        tmp = 0
        if w + s > F:
            continue
        if w+s == 0:
            continue
        if s > (w / 100)*E:
            continue
        tmp = (100*s)/(w+s)
        if tmp >= conc:
            conc = tmp
            W = w
            S = s
        #print(conc,w,s)
print(W+S,S)

Submission status: Accepted

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

water = set()
for i in range(F//(100*A) + 1):
    for j in range(F // (100*B) + 1):
        if 100*A * i + 100*j*B <= F:
            water |= {100*A * i + 100*j*B}
        else:
            break

sugar = set()
for i in range(F//C + 1):
    for j in range(F // D + 1):
        if C * i + D*j <= F:
            sugar |= {C * i + D*j}
        else:
            break
ans = [100*A, 0]
for x in water:
    if x == 0:
        continue
    for y in sugar:
        if x + y <= F and y <= (x/100)*E:
            if ans[1]/ans[0] < y / (x+y):
                ans = [x+y, y]

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

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
# + 100a 水
# + 100b 水
# + c 砂糖
# + d 砂糖
# 100gの水にe[g]のsugar
# 水と砂糖の合計はf以下。溶け残し厳禁

def s_max(w):
    ret1 = e*w/100
    ret2 = f-w
    s = min(int(ret1),int(ret2)) #砂糖の最大量
    dp = [False]*(s+1)
    dp[0] = True
    for i in range(s+1):
        for j in range(s+1):
            if j + i*c <= s:
                dp[j+i*c] = dp[j]
    for i in range(s+1):
        for j in range(s+1):
            if j + i*d <= s:
                dp[j+i*d] = dp[j+i*d] or dp[j]
    ret = 0 
    for i in range(s+1):
        if dp[i]: ret = i
    return ret

dp = [False] * ((f//100)+1)
dp[0] = True
for i in range(30):
    for j in range(f+1):
        if j+i*a <= f//100:
            dp[j+i*a] = dp[j]
for i in range(30):
    for j in range(f+1):
        if j+i*b <= f//100:
            dp[j+i*b] = dp[j]

nmax = (0,(a*100,0))
for i in range((f//100)+1):
    if dp[i]:
        w = i*100
        s = s_max(i*100)
        if w+s == 0:
            continue
        if nmax[0] <= s/(s+w):
            nmax = (s/(s+w),(s+w,s))
print(*nmax[1])

Submission status: Accepted

Solution code:
def main():
    a, b, c, d, e, f = map(int, input().split())
    sugar = 0
    water = 0
    con = 0
    for i in range(f//100+1):
        if i%b == 0 or i%a == 0:
            w = i*100
            x = min(f-w, i*e)
            s = 0
        for j in range(x//c+1):
            ss = j*c
            s = max(s,ss+((x-ss)//d)*d)
        if w != 0:
            if con <= (100*s)/(w+s):
                water = w
                sugar = s
                con = (100*s)/(w+s)
    print(sugar+water, sugar)

if __name__ == "__main__":
    main()