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

n = f//(100*a)
m = f//(100*b)
p = f//c
q = f//d

mx = 0
state = True
for k in range(p+1):
    for l in range(q+1):
        for i in range(n+1):
            for j in range(m+1):
                if i == 0 and j == 0:
                    continue
                s = 100*a*i+100*b*j
                t = c*k+d*l
                u = 100*t/s
                if s + t> f:
                    continue
                if u > e:
                    continue
                if mx < u:
                    state = False
                    mx = u
                    ans1, ans2 = s+t, t
                    if mx == e:
                        print(ans1, ans2)
                        exit()
if state:
    print(100*a, 0)
else:
    print(ans1, ans2)

Submission status: Accepted

Solution code:
import itertools
A, B, C, D, E, F = [int(_) for _ in input().split()]
W = [0] * (F+1)
S = [0] * (F+1)
for a, b in itertools.product(range(F // (100*A) + 1), range(F//(100*B) + 1)):
    if 100*A*a+100*B*b <= F:
        W[100*A*a+100*B*b] = min(E*(A*a+B*b), F-100*A*a-100*B*b)

for c, d in itertools.product(range(F // C + 1), range(F // D + 1)):
    if C*c+D*d <= F:
        S[C*c+D*d] = C*c+D*d
for i in range(F):
    if S[i+1] == 0:
        S[i+1] = S[i]
water = 100*A
sugar = 0
for i in range(1, F+1):
    if W[i] and S[W[i]]/i > sugar/water:
        sugar, water = S[W[i]], i
print(sugar+water, sugar)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = [int(i) for i in input().split()]
waterA = [a * 100 * i for i in range(int(f / (100 * a)) + 1)]
waterB = [b * 100 * i for i in range(int(f / (100 * b)) + 1)]
sugarC = [c * i for i in range(int(f / c) + 1)]
sugarD = [d * i for i in range(int(f / d) + 1)]

# まず水が何100gにできるかを算出(<F)
_water = []
for i in range(len(waterA)):
    for j in range(len(waterB)):
        if 100 * a * i + 100 * b * j <= f:
            _water.append(100 * a * i + 100 * b * j)
_water = sorted(_water)[1:]
water = [_water[0]]
for i in range(1, len(_water)):
    if _water[i] != _water[i - 1]:
        water.append(_water[i])
# 砂糖が何gにできるかを算出(<F)
_sugar = []
for i in range(len(sugarC)):
    for j in range(len(sugarD)):
        if c * i + d * j <= f:
            _sugar.append(c * i + d * j)
_sugar = sorted(_sugar)
sugar = [_sugar[0]]
for i in range(1, len(_sugar)):
    if _sugar[i] != _sugar[i - 1]:
        sugar.append(_sugar[i])
# print(water)
# print(sugar)
# 各場合で砂糖の最大量を計算
maxSugar = [-1, -1, -1]  # [dense, sugar, total]
for i in range(len(sugar)):
    for j in range(len(water)):
        if sugar[i] + water[j] > f:
            continue
        elif maxSugar[0] < sugar[i]/(sugar[i]+water[j]) <= e/(100+e):
            maxSugar[0] = sugar[i]/(sugar[i]+water[j])
            maxSugar[1] = sugar[i]
            maxSugar[2] = sugar[i] + water[j]
        # print("s:{} w:{} dense:{}".format(sugar[i], water[j], sugar[i]/(sugar[i]+water[j])))
# print(e/(100+e))
if maxSugar[0] == -1:
    print("1 0")
else:
    print("{} {}".format(maxSugar[2], maxSugar[1]))

Submission status: Accepted

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

sug = 0
sugwat = 100 * a
for h in range(0,f + 1,100 * a):
    if h > f:
        break
    for i in range(0, f + 1, 100 * b):
        if h + i > f:
            break
        for j in range(0, f + 1, c):
            if h + i + j <= f:
                if h + i + j > 0:
                    if 100 * (j / (h + i + j)) > 100 * (e / (100 + e)):
                        break
            else:
                break
            for k in range(0, f + 1, d):
                if h + i + j + k <= f:
                    if h + i + j + k > 0:
                        if 100 * ((j + k) / (h + i + j + k)) <= 100 * (e / (100 + e)):
                            if 100 * (sug / sugwat) <= 100 * ((j + k) / (h + i + j + k)):
                                sugwat = h + i + j + k
                                sug = j + k
                else:
                    break

print(sugwat, sug)

Submission status: Accepted

Solution code:
# encoding: utf-8
A, B, C, D, E, F = map(int, input().split())

max_rate = 0
ans = (1, 0, 0, 0)
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        # escape
        if water == 0: continue # avoid 0 div.
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        # search (safer version)
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for k in list(range(salt_upper // C + 1))[::-1]:
            for l in list(range(salt_upper // D + 1))[::-1]:
                salt = k * C + D * l
                # escape
                if salt == 0: continue
                elif salt / water > E: continue
                elif salt + 100 * water > F: continue
                # judge (only for max l)
                if salt / water > max_rate_tmp:
                    ans_tmp = (i, j, k, l)
                    max_rate_tmp = salt / water
                break
        # end loop
        if max_rate_tmp == 0: continue
        elif max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans = []
water = []
for i in range(31):
    for j in range(31):
        tmp = 100*i*A + 100*j*B
        if tmp <= F:
            water.append(tmp)
water = list(set(water))
water.remove(0)

sugar = []
for i in range(101):
    for j in range(101):
        tmp = i*C + j*D
        if tmp <= F:
            sugar.append(tmp)
sugar = list(set(sugar))
sugar.remove(0)

            
for miz in water:
    for sato in sugar:
        if miz + sato <= F and sato / (miz + sato) <= E / (100 + E):
            ans.append([miz, sato, sato / (miz + sato)])
            
if ans:
    ans.sort(key=lambda x:x[2], reverse = True)
    print(ans[0][0]+ans[0][1], ans[0][1])
else:
    print(water[0], 0)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
a*=100
b*=100
res=chk=0
ans=[]

for i in range(16):
    for j in range(16):
        for k in range(1501):
            w=(i*a)+(j*b)
            s=(k*c)
            o=(w//100)*e
            if w==0:
                pass
            elif w+s>f or s>o:
                break
            else:
                s+=(min(f-w-s,o-s)//d)*d
                if len(ans)==0:
                    ans=[s/(w+s),w+s,s]
                elif s/(w+s)>ans[0]:
                    ans=[s/(w+s),w+s,s]
print(ans[1],ans[2])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
x = []
y = []
t = 100 * e / (100 + e)
for i in range(f // (100 * a) + 1):
    bb = f - 100 * a * i
    for j in range(bb // (100 * b) + 1):
        if 100 * (a * i + b * j) in x:
            continue
        else:
            x.append(100 * (a * i + b * j))
for i in range(f // c + 1):
    dd = f - c * i
    for j in range(dd // d + 1):
        if c * i + d * j in y:
            continue
        else:
            y.append(c * i + d * j)
y.sort()
rr = 0
ans = []
for i, xi in enumerate(x):
    for j, yi in enumerate(y):
        if xi + yi == 0:
            continue
        r = 100 * yi / (xi + yi)
        if r > t:
            break
        elif xi + yi <= f and rr <= r:
            ans = [xi + yi, yi]
            rr = r
print(ans[0], ans[1])

Submission status: Accepted

Solution code:
A = list(map(int, input().split()))
sugar = []
water = []
if A[2] == 1:
    sugar = [i for i in range(A[5]+1)]
else:
    for i in range(10 + (1 + A[5])//A[2]):
        for j in range(10 + (A[5]-A[2]*i+1)//A[3]):
            if A[2] * i + A[3] * j not in sugar and A[2] * i + A[3] * j <= 3000:
                sugar.append(A[2] * i + A[3] * j)
for i in range(2 + 31//A[0]):
    for j in range(2 + (31 - i)//A[1]):
        if A[0] * i + A[1] * j <= 30 and A[0] * i + A[1] * j not in water:
            water.append(A[0] * i + A[1] * j)
ans = 0
anssugar = 0
answater = min(A[0], A[1]) * 100
for i in sugar:
    for j in water:
        if i + j != 0:
            if ans < 100.0 * i / (i + j) and (i + 100 * j) <= A[5] and i  <= j * A[4]:
                ans = 100.0 * i / (i + j)
                anssugar = i
                answater = 100 * j

print(str(anssugar + answater)+" "+str(anssugar))

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
waters,sugars = [],[]
ans_w = 0
ans_s = 0
ans_d = 0

for i in range(0,f//100+1):
    for j in range(0,f//100+1):
        w = 100*a*i + 100*b*j
        if w < f:
            waters.append(w)

for i in range(0,f+1):
    for j in range(0,f+1):
        s = c*i + d*j
        if s < f:
            sugars.append(s)

for w in waters:
    for s in sugars:
        if (w+s) <= f:
            s_e = w/100 * e
            if s_e < s or w+s == 0:
                continue
            if (100*s/(w+s)) > ans_d:
                ans_w = w
                ans_s = s
                ans_d = 100*s/(w+s)

if ans_w == ans_s == ans_d == 0:
    print('%d 0' % (a*100))
else:
    print('%d %d' % (ans_w+ans_s,ans_s))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
a_num = int(F/(100*A))
b_num = int(F/(100*B))
c_num = int(F/C)
concentration = 0
ans1 = 100*A
ans2 = 0
for i in range(a_num+1):
    a = i*100*A
    for j in range(b_num+1):
        b = j*100*B
        if a+b > F:
            break
        for k in range(c_num+1):
            c = k*C
            if a+b+c > F:
                break
            if ((a+b)/100)*E < c:
                break
            limit_e = ((a+b)/100)*E - c
            limit_f = F - (a+b+c)

            d = min(int(limit_e/D)*D, int(limit_f/D)*D)
            if d < 0:
                break
            if a+b+c+d == 0:
                break
            _concentration = (100*(c+d))/(a+b+c+d)
            if _concentration > concentration:
                concentration = _concentration
                ans1 = a+b+c+d
                ans2 = c+d
print(ans1, ans2)

Submission status: Accepted

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

m = sys.maxsize
mlist = [1,0,0,0]

for x in range(int(f / (100*a)) + 1):
    for y in range(int((f - 100 * a * x) / 100*b) + 1):
        for z in range(min(int((f - 100* a * x - 100 * b * y) / c), int(((a*x + b*y) * e) / c)) + 1):
            for w in range(min(int((f - 100* a * x - 100 * b * y - c * z) / d), int(((a*x + b*y) * e - c*z) / d)) + 1):
                if (z != 0 or w != 0) and float((a*x + b*y) / (c*z + d*w)) <= m:
                    mlist = [x,y,z,w]
                    m = float((a*x + b*y) / (c*z + d*w))
print(100 * a * mlist[0] + 100 * b * mlist[1] + c * mlist[2] + d * mlist[3], c * mlist[2] + d * mlist[3])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    a, b, c, d, e, f = map(int, input().split())
    concentration = 0
    water_set = set()
    sugar_set = set()

    # See:
    # https://www.youtube.com/watch?v=nCHz87GMdpo
    for i in range(f + 1):
        for j in range(f + 1):
            y = c * i + d * j

            if y <= f:
                sugar_set.add(y)

    for k in range(0, f + 1, 100):
        for l in range(0, f + 1, 100):
            x = a * k + b * l

            if 0 < x <= f:
                water_set.add(x)

    sugar_water_amount = min(water_set) + min(sugar_set)
    sugar_amount = min(sugar_set)

    for water in water_set:
        for sugar in sugar_set:
            if (water + sugar <= f) and (sugar <= e * (water // 100)):
                candidate = (100 * sugar) / (water + sugar)

                if candidate > concentration:
                    concentration = candidate
                    sugar_water_amount = water + sugar
                    sugar_amount = sugar

    print(sugar_water_amount, sugar_amount)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

n = [[0, 0] for _ in range(f + 1)]
n[a][0] = a
for i in range(f + 1 - a):
    if n[i][0] != 0:
        n[i + a][0] = n[i][0] + a
if f >= b:
    n[b][0] = b
    for i in range(f + 1 - b):
        if n[i][0] != 0:
            n[i + b][0] = n[i][0] + b
for i in range(f + 1 - c):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (c + n[i][1]) / tmpt <= e and n[i + c][1] / (i + c) < (n[i][1] + c) / (i + c):
            n[i + c][0] = n[i][0]
            n[i + c][1] = n[i][1] + c
for i in range(f + 1 - d):
    if n[i][0] == 0:
        continue
    tmpt = n[i][0] / 100
    if (d + n[i][1]) / tmpt <= e and n[i + d][1] / (i + d) < (n[i][1] + d) / (i + d):
            n[i + d][0] = n[i][0]
            n[i + d][1] = n[i][1] + d
maxp = [0, a, 0]
for i in range(len(n)):
    if(n[i][1] != 0 and maxp[0] < n[i][1] / i):
        maxp = [n[i][1] / i] + n[i]
print(str(maxp[1] + maxp[2]) + ' ' + str(maxp[2]))

Submission status: Accepted

Solution code:

def 解():
    iA,iB,iC,iD,iE,iF = [int(_) for _ in input().split()]
    #結局全検索
    d = {}
    def searchAll(d,bF): # bF=0 Eにちかづける
        iMaxA = iF // 100*iA
        for i in range(iMaxA+1):
            iMaxB = (iF - 100*iA*i) // iB
            for j in range(iMaxB + 1):
                if i==0 and j==0:
                    continue
                iAB = 100*iA*i + 100*iB*j
                iUlim = iAB * iE //100
                if bF:
                    iUlim = min(iUlim,iF-iAB)
                else:
                    if iUlim > iF - iAB:
                        continue
                iMaxC = iUlim //iC
                for k in range(iMaxC+1):
                    l = (iUlim - iC*k ) //iD
                    iCD = iC*k +iD*l
                    if iUlim -iCD == 0:
                        print(iAB +iCD,iCD)
                        exit()
                    else:
                        iKey = iUlim-iCD
                        if not iKey in d:
                            d[iKey] = (iAB +iCD,iCD)
        return d
    d = searchAll(d,0)
    if not d:
        d = searchAll(d,1)
    iMin = min(d.keys())
    print(" ".join(map(str,d[iMin])))

解()

Submission status: Accepted

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

max_c = 0
ans_sw = A*100
ans_s = 0

water = set()
for a in range(0, F + 1, A * 100):
    for b in range(0, F - a + 1, B * 100):
        water.add(a + b)

suger = set()
for c in range(0, F + 1, C):
    for d in range(0, F - c + 1, D):
        suger.add(c + d)

for w in water:
    for s in suger:
        
        if s <= E * w // 100 and 0 < w + s <= F:
            c = s / (w + s)
            if max_c < c:
                max_c = c
                ans_sw = s + w
                ans_s = s

print(ans_sw, ans_s)

Submission status: Accepted

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

w = 0
s = 0
max_s = f * e // (100 + e)
max_a = f // (a * 100)
max_b = f // (b * 100)
max_c = max_s // c
max_d = max_s // d

ans = 0
ans_s = 0
ans_w = 0
for ia in range(max_a + 1):
    for ib in range(max_b + 1):
        temp_w = (ia * a + ib * b) * 100
        if temp_w > f:
            break
        for ic in range(max_c + 1):
            for id in range(max_d + 1):
                temp_s = ic * c + id * d
                if temp_s > min(temp_w * e / 100, f - temp_w):
                    break
                elif temp_s + temp_w > 0:
                    temp = temp_s / (temp_s + temp_w)
                    if temp >= ans:
                        ans = temp
                        ans_s = temp_s
                        ans_w = temp_w

print((ans_w + ans_s), ans_s)

Submission status: Accepted

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

water = set()
for i in range(0, f + 1, 100 * a):
    for j in range(0, f - a + 1, 100 * b):
        water.add(i + j)

sugar = set()
for i in range(0, f + 1, c):
    for j in range(0, f - c + 1, d):
        sugar.add(i + j)

max_r = -1
max_sw = -1
max_s = -1
for w in water:
    for s in sugar:
        if 0 < w + s <= f and s <= w * e // 100:
            r = s / (w + s)
            if max_r < r:
                max_r = r
                max_sw = s + w
                max_s = s

print(max_sw, max_s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools

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

ope1 = [x for x in range(F//(100*A)+1)]
ope2 = [x for x in range(F//(100*B)+1)]
ope3 = [x for x in range(F//C+1)]
ope4 = [x for x in range(F//D+1)]

water = []
for a,b in itertools.product(ope1, ope2):
    temp = 100*a*A + 100*b*B
    water.append(temp)
water = sorted(list(set(water)))

sugar = []
for c,d in itertools.product(ope3, ope4):
    temp = c*C + d*D
    sugar.append(temp)
sugar = sorted(list(set(sugar)))

ans_list = []
for w,s in itertools.product(water, sugar):
    if w == 0:
        continue
    if s/(w//100) > E:
        continue
    if w+s > F:
        continue
    ans_list.append([s*100/(s+w),s+w,s])

if len(ans_list) > 0 :
    ans_list.sort(key=lambda x:x[0])
    print(ans_list[-1][1],ans_list[-1][2])
else:
    print(100*A,0)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
Smax = E * F // 100
S, W = [False for i in range(Smax+1)], [False for i in range(F+1)]
S[0], W[0] = True, True
for i in range(1, len(S)):
    if i - C >= 0:
        if S[i-C] == True:
            S[i] = True
    if i - D >= 0:
        if S[i-D] == True:
            S[i] = True
for i in range(1, F+1):
    if i - A >= 0:
        if W[i-A] == True:
            W[i] = True
    if i - B >= 0:
        if W[i-B] == True:
            W[i] = True

conc = 0
ans = [A, 0]
for i in reversed(range(len(S))):
    if S[i] == True:
        for j in range(1, F-i+1):
            if W[j] == True and 100 * i <= j * E:
                if 100 * i / (i+j) > conc:
                    conc = 100 * i / (i+j)
                    ans = [i+j, i]
                    break
print(" ".join(map(str, ans)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A, B, C, D, E, F = map(int, input().split())

i = 0
j = 0
X = []

while A*i <= F:
    j = 0
    while A*i + B*j <= F:
        X.append(A*i + B*j)
        j += 100
    i += 100
X = sorted(list(set(X)))

i = 0
j = 0
Y = []

while C*i <= F:
    j = 0
    while C*i + D*j <= F:
        Y.append(C*i + D*j)
        j += 1
    i += 1
Y = sorted(list(set(Y)))

ans1 = X[1]
ans2 = 0
max_con = 0

for x in X[1:]:
    for y in Y:
        if x + y > F:
            break
        elif x + y != 0:
            con = 100*y / (x + y)
            if con > max_con and y <= E*x/100:
                ans1 = x + y
                ans2 = y
                max_con = con

print(ans1,ans2)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
w = []
for k in range(f//(100*a)+1):
  x = a*k
  while x <= f//100:
    w += [x]
    x += b    
s = []
for k in range(f//c+1):
  x = c*k
  while x <= f:
    s += [x]
    x += d
  
p,q = a,0    
for x in w:
  if x == 0:
    continue
  for y in s:
    if 100*x+y <= f and y/x <= e and y/x > q/p:
      p,q = x,y
print(100*p+q,q)

Submission status: Accepted

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

W = set()
for a in range(0, F+1, 100 * A):
    for b in range(0, F - a+1, 100 * B):
        W.add(a + b)

S = set()
for c in range(0, F+1, C):
    for d in range(0, F - c+1, D):
        S.add(c + d)

mx = -1
for w in W:
    for s in S:
        if 0 < w + s <= F and s <= w * E // 100:
            if mx < s/(w+s):
                ans = w+s, s
                mx = s/(w+s)
print(ans[0], ans[1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Oct  8 14:30:54 2018
ABC074C
@author: maezawa
"""

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

pos_water = set([])
pos_sugar = set([])
max_water = f
max_sugar = f*e//100

for i in range(max_water//100//a+1):
    for j in range(max_water//100//b+1):
        if 100*(i*a + j*b) > max_water:
            break
        else:
            pos_water.add(100*(i*a + j*b))

for i in range(max_sugar//c+1):
    for j in range(max_sugar//d):
        if i*c + j*d > max_sugar:
            break
        else:
            pos_sugar.add(i*c + j*d)

water = list(pos_water)
water.sort()
sugars = list(pos_sugar)
sugars.sort()
water.remove(0)

#print(water)
#print(sugars)

ans_weight = water[0]
ans_sugar = 0
max_conc = 0
for w in water:
    for s in sugars:
        conc = s/(s+w)
        weight = s+w
        #print(w, s, conc, weight)
        if weight > f:
            break
        if conc > e/(100+e):
            break
        if conc > max_conc:
            max_conc = conc
            ans_weight = weight
            ans_sugar = s

print(ans_weight, ans_sugar)

Submission status: Accepted

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

waters = set()
for b in range(0, F+1, 100*B):
    for a in range(0, F-b+1, 100*A):
        waters.add(a+b)
waters.remove(0)

sugars = set()
for d in range(0, F+1, D):
    for c in range(0, F-d+1, C):
        sugars.add(c+d)

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)

Submission status: Accepted

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

water_set = set()
sugar_set = set()

for a in range(0, F+1, 100*A):
    for b in range(0, F+1, 100*B):
        if a + b <= F:
            water_set.add(a + b)

for c in range(0, F+1, C):
    for d in range(0, F+1, D):
        if c + d <= F//2 + 1:
            sugar_set.add(c + d)

water_set.remove(0)
water_list = list(water_set)
sugar_list = list(sugar_set)

cons = -1
water_ans = 0
sugar_ans = 0
for water in water_list:
    for sugar in sugar_list:
        if water + sugar <= F and sugar * 100 <= E * water:
            if 100 * sugar / (water + sugar) > cons:
                cons = 100 * sugar / (water + sugar)
                water_ans = water
                sugar_ans = sugar

print(water_ans + sugar_ans, sugar_ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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

water_set = set()
sugar_set = set()

MAX = 3000

# ありうる水と砂糖の重さ
for ai in range(0,MAX//100+1,a):
    for bi in range(0,MAX//100+1,b):
        if 100 * (ai + bi) <= MAX:
            water_set.add(100 * (ai + bi))

water_list = sorted(list(water_set))
water_list.remove(0)

for ci in range(0,30*e+1,c):
    for di in range(0,30*e+1,d):
        if ci + di <= 30*e:
            sugar_set.add(ci+di)
            
sugar_list = sorted(list(sugar_set))

node_max = -1
sw = 0
sg = 0

for wi in water_list:
    for si in sugar_list:
        if wi+si <= f and si <= e * (wi//100) and wi+si > 0:
            node = (100*si) / (wi+si)
            if node > node_max:
                sw = si + wi
                sg = si
                node_max = node
                
print(sw,sg)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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

water_set = set()
sugar_set = set()

MAX = 3000

# ありうる水と砂糖の重さ
for ai in range(0,MAX//100+1,a):
    for bi in range(0,MAX//100+1,b):
        if 100 * (ai + bi) <= MAX:
            water_set.add(100 * (ai + bi))

water_list = sorted(list(water_set))

for ci in range(0,30*e+1,c):
    for di in range(0,30*e+1,d):
        if ci + di <= 30*e:
            sugar_set.add(ci+di)
            
sugar_list = sorted(list(sugar_set))

node_max = -1
sw = 0
sg = 0

for wi in water_list:
    for si in sugar_list:
        if wi+si <= f and si <= e * (wi//100) and wi+si > 0:
            node = (100*si) / (wi+si)
            if node > node_max:
                sw = si + wi
                sg = si
                node_max = node
                
print(sw,sg)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
num = (0, 0)
rec = 0
for a in range(101):
    for b in range(101):
        if a * A * 100 + b * B * 100 > F:
            break
        for c in range(100):
            if a * A * 100 + b * B * 100 + c * C > F:
                break
            for d in range(100):
                q = a * A * 100 + b * B * 100
                p = C * c + D * d
                if p > E * (a * A + b * B):
                    continue
                if p + q == 0:
                    continue
                if p + q <= F:
                    if rec <= 100 * p / (p + q):
                        rec = 100 * p / (p + q)
                        num = (p + q, p)
                else:
                    break

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

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
total = 0
sugar = 0
p,q,r,s = 0,0,0,0
p_max,q_max,r_max,s_max = 0,0,0,0
p_max = f // (100*a)
q_max = f // (100*b)
r_max = int((0.01 * f * e) // c)
s_max = int((0.01 * f * e) // d)
set_water = set()
set_sugar = set()

for p in range(0,p_max+1):
    for q in range(0,q_max+1):
        if 100*(a*p + b*q) <= f:
            set_water.add(100*(p*a+q*b))
for r in range(0,r_max+1):
    for s in range(0,s_max+1):
        if c*r + d*s <= 0.01*f*e:
            set_sugar.add(r*c+s*d)
conc_max = 0
max_sugar = 0
max_tot = 0
for water in set_water:
    for sugar in set_sugar:
        if water + sugar > f:
            pass
        elif water == 0 or sugar == 0:
            pass
        elif sugar / water > 0.01*e:
            pass
        else:
            conc = sugar / (water+sugar)
            if conc >= conc_max:
                conc_max = conc
                max_sugar = sugar
                max_tot = water+sugar
            else:
                pass
if max_tot == 0:
    max_tot = 100*a
print(max_tot,max_sugar)

Submission status: Accepted

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

m=int(f*(e/100))
for i in range(0,m+1,c):
  for j in range(0,m-i+1,d):
     y.add(i+j)
x.remove(0) 
z=[-1]
ans=[]
for i in x:
  for j in y:
    if i+j<=f and j*100/(i+j)<=e*100/(100+e):
      if j*100/(i+j)>max(z):
        z.append(j*100/(i+j))
        ans.append([i+j,j])
        
print(ans[-1][0],ans[-1][1])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = list(map(int, input().split()))
res = [0, 0]
w = set()
s = set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        total = a*i*100 + b*j*100
        if a*i*100 + b*j*100 <= f:
            w.add(total)
w.remove(0)

s_max = int(f * (e / 100))
for i in range(0, s_max+1, c):
    for j in range(0, s_max-i+1, d):
        s.add(i+j)

max_nodo = -1
for wtr in w:
    for sgr in s:
        nodo = (sgr * 100) / (wtr + sgr)
        if wtr + sgr <= f and nodo <= (e*100) / (e+100):
            if nodo > max_nodo:
                max_nodo = nodo
                res[0] = wtr+sgr
                res[1] = sgr

print(str(res[0]) + " " + str(res[1]))

Submission status: Accepted

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

water = {}
for i in range(A[5]//(100*A[0])+1):
    for j in range((A[5]-i*A[0]*100)//(100*A[1])+1):
        water[100*(A[0]*i+A[1]*j)]=1
water.pop(0)

ans = [100*A[0], 0]
max_ = -1

for w in water.keys():
    for c in range(min((w//100*A[4])//A[2]+1,(A[5]-w)//A[2]+1)):
        d = min(((w//100*A[4])-c*A[2])//A[3], (A[5]-w-c*A[2])//A[3])
        tmp = (A[2]*c+A[3]*d)/(w+A[2]*c+A[3]*d)
        if max_ < tmp and (w+A[2]*c+A[3]*d) <= A[5]:
            ans=[w+A[2]*c+A[3]*d, A[2]*c+A[3]*d]
            max_=tmp

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