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: Wrong Answer

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

ws = set()
i = j = 0
while True:
    j = 0
    if B*i > F//100: break
    while True:
        w = B*i + A*j
        if w > F//100: break
        ws.add(w)
        j += 1
    i += 1
ws = list(ws)
ws.sort()

ss = set()
i = j = 0
while True:
    j = 0
    if D*i > F: break
    while True:
        s = D*i + C*j
        if s > F: break
        ss.add(s)
        j += 1
    i += 1
ss = list(ss)
ss.sort()

limit = E / (100+E)
sugar = 1
water = rate = 0
for w in ws:
    w = w*100
    if w == 0: continue
    if w > F: break
    for s in ss:
        if w+s > F: break
        r = s / (w+s)
        if r > limit: break
        if r > rate:
            rate = r
            water = w
            sugar = s
print(water+sugar, sugar)

Submission status: Wrong Answer

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

x = 0
y = 0
z = 0

a = 0
while a <= F:
    b = 0
    while a + b <= F:
        c = 0
        while a + b + c <= F:
            d = 0
            while a + b + c + d <= F:
                if a + b == 0 or (c + d) / (a + b) > E / 100:
                    break
                if (c + d) / (a + b + c + d) > z:
                    x = a + b + c + d
                    y = c + d
                    z = y / x
                d += D
            c += C
        b += 100 * B
    a += 100 * A

print(" ".join(map(str, [x, y])))

Submission status: Wrong Answer

Solution code:
def func(a, b):
    return (100 * b) / (a + b)

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

a = float(100 * A)
b = float(100 * B)
c = float(C)
d = float(D)
f = F

con = 0
maxes = [0, 0]

q = [[a, c], [a, d], [b, c], [b, d]]


while len(q) != 0:
    tmp = []
    key = q.pop(0)
    if func(key[0], key[1]) > con and key[0] + key[1] <= f:
        tmp += [key[0] + a, key[1] + c]
        tmp += [key[0] + a, key[1] + d]
        tmp += [key[0] + b, key[1] + c]
        tmp += [key[0] + b, key[1] + d]
        con = func(key[0], key[1])
        maxes[0], maxes[1] = key[0], key[1]

    if len(tmp) > 0:
        q.append(tmp)

print key[0], key[1]

Submission status: Wrong Answer

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

x = 0
y = 0
z = 0

a = 0
while a <= F:
    b = 0
    while a + b <= F:
        c = 0
        while a + b + c <= F:
            if a + b == 0:
                break
            d = 0
            while a + b + c + d <= F:
                if (c + d) / (a + b) > E / 100:
                    break
                if (c + d) / (a + b + c + d) > z:
                    x = a + b + c + d
                    y = c + d
                    z = y / x
                d += D
            c += C
        b += 100 * B
    a += 100 * A

print(" ".join(map(str, [x, y])))

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D,E,F = map(int, input().split())
result_noudo=None
result_satosui=None
result_sato=None

for a in range(math.floor(F/100*A)+1):
    for b in range(math.floor((F-100*A*a)/100*B)+1):
        for c in range(math.floor((F-100*A*a-100*B*b)/C)+1):
            for d in range(math.floor((F-100*a*A-100*b*B-C*c)/D)+1):
                sum_under=100*a*A+100*b*B+C*c+D*d
                if (a==0 and b==0) or (d==0 and c==0):
                    continue
                sum_top=C*c+D*d
                noudo=(100*sum_top)/sum_under
                if sum_under<=F and noudo<=(100*E)/(100+E) and (result_noudo==None or noudo>result_noudo):
                    result_noudo=noudo
                    result_satosui=sum_under
                    result_sato=sum_top
print(str(result_satosui)+" "+str(result_sato))

Submission status: Wrong Answer

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


t = min(A,B)
w += t * 100
l = t * E
c =(l // C) * C
d = (l // D) * D

s = 0
for i in range(c+1):
    for j in range(d+1):
        k = i * C + j *D
        if k <= l:
            s = max(k,s)
print(w+s, s)

Submission status: Wrong Answer

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

ws = set()
i = j = 0
while True:
    j = 0
    if B*i > F//100: break
    while True:
        w = B*i + A*j
        if w > F//100: break
        ws.add(w)
        j += 1
    i += 1
ws = list(ws)
ws.sort()

ss = set()
i = j = 0
while True:
    j = 0
    if D*i > F: break
    while True:
        s = D*i + C*j
        if s > F: break
        ss.add(s)
        j += 1
    i += 1
ss = list(ss)
ss.sort()

limit = E / (100+E)
water = sugar = rate = 0
for w in ws:
    w = w*100
    if w == 0: continue
    if w > F: break
    for s in ss:
        if w+s > F: break
        r = s / (w+s)
        if r > limit: break
        if r > rate:
            rate = r
            water = w
            sugar = s
print(water+sugar, sugar)

Submission status: Wrong Answer

Solution code:

ABCDEF = input()
split_ABCDEF = ABCDEF.split()
int_split_ABCDEF = [int(i) for i in split_ABCDEF]
A = int_split_ABCDEF[0]*100
B = int_split_ABCDEF[1]*100
C = int_split_ABCDEF[2]
D = int_split_ABCDEF[3]
E = int_split_ABCDEF[4]
F = int_split_ABCDEF[5]

if A > B:
    sugar = int((B / 100) * E)
    print("{} {}".format(sugar+B, sugar))
else:
    sugar = int((A / 100) * E)
    print("{} {}".format(sugar+A, sugar))

Submission status: Wrong Answer

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

ws = set()
i = j = 0
while True:
    j = 0
    if B*i > F//100: break
    while True:
        w = B*i + A*j
        if w > F//100: break
        ws.add(w)
        j += 1
    i += 1
ws = list(ws)
ws.sort()

ss = set()
i = j = 0
while True:
    j = 0
    if D*i > F: break
    while True:
        s = D*i + C*j
        if s > F: break
        ss.add(s)
        j += 1
    i += 1
ss = list(ss)
ss.sort()

limit = E / (100+E)
water = sugar = rate = 0
for w in ws:
    w = w*100
    if w == 0: continue
    if w >= F: break
    for s in ss:
        if w+s >= F: break
        r = s / (w+s)
        if r > limit: break
        if r > rate:
            rate = r
            water = w
            sugar = s
print(water+sugar, sugar)

Submission status: Wrong Answer

Solution code:
A,B,C,D,E,F=[int(x) for x in input().split()]
from itertools import product
def gauss(i):
    return F//i+1
waters=set()
sugers=set()
ans=(100*A,0)
for a,b in product(range(gauss(A)),range(gauss(B))):
    waters.add(100*(a*A+b*B))
for c,d in product(range(gauss(C)),range(gauss(D))):
    sugers.add(c*C+d*D)
for water,suger in product(waters,sugers):
    if water==0:
        continue
    if water+suger>F:
        continue
    if 100*suger>E*(water+suger):
        continue
    if ans[1]*(water+suger)<suger*ans[0]:
        ans=(water+suger,suger)
print(ans[0],ans[1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

def main():
    A, B, C, D, E, F = [int(x) for x in input().split()]
    N = F // 100
    max_rate = E / (100 + E)
    best_weight, best_suger, best_rate = 0, 0, 0.0
    for a in range(N+1):
        for b in range(N - a*A + 1):
            water = (a*A+b*B)*100
            if water > F:
                continue
            for c in range(F - water + 1):
                for d in range(F - water - c*C + 1):
                    suger = c*C + d*D
                    if water + suger > F:
                        continue
                    if water + suger == 0:
                        rate = 0.0
                    else:
                        rate = suger / (water + suger)
                    if rate > max_rate:
                        continue
                    if rate > best_rate:
                        best_weight = water + suger
                        best_suger = suger
                        best_rate = rate
    print(best_weight, best_suger)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A,B,C,D,E,F=[int(x) for x in input().split()]
from itertools import product
def gauss(i):
    return F//i+1
waters=set()
sugers=set()
ans=(100*A,0)
for a,b in product(range(gauss(A)),range(gauss(B))):
    waters.add(100*(a*A+b*B))
for c,d in product(range(gauss(C)),range(gauss(D))):
    sugers.add(c*C+d*D)
for water,suger in product(waters,sugers):
    if water==0:
        continue
    if water+suger>F:
        continue
    if 100*suger>E*(water+suger):
        continue
    if ans[1]*(water+suger)<suger*ans[0]:
        ans=(water+suger,suger)
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

import itertools

def main():
    A, B, C, D, E, F = [int(x) for x in input().split()]
    N = F // 100
    max_rate = E / (100 + E)
    best_weight, best_suger, best_rate = 0, 0, 0.0
    for a in range(N):
        for b in range(N - a*A):
            water = (a*A+b*B)*100
            if water > F:
                continue
            for c in range(F - water):
                for d in range(F - water - c*C):
                    suger = c*C + d*D
                    if water + suger > F:
                        continue
                    if water + suger == 0:
                        rate = 0.0
                    else:
                        rate = suger / (water + suger)
                    if rate > max_rate:
                        continue
                    if rate > best_rate:
                        best_weight = water + suger
                        best_suger = suger
                        best_rate = rate
    print(best_weight, best_suger)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d,e,f=map(int, input().split())
amax=f//(a*100)
bmax=f//(b*100)
c_list=[]
sw_list=[]
s_list=[]

for i in range(amax+1):
   for j in range(bmax+1):
       water=100*a*i+100*b*j
       if f>=water>0:
           smax=f-water
           for k in range(smax+1):
               for l in range(smax+1):
                   sugar=c*k+d*l
                   if water*e/100>=sugar and water+sugar<=f:
                       concentration=100*sugar/(water+sugar)
                       c_list.append(concentration)
                       sw_list.append(sugar+water)
                       s_list.append(sugar)

num=c_list.index(max(c_list))
print(sw_list[num],s_list[num])

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d,e,f = map(int, input().split())
con = list()
s = list()
for x in range(31):
    for y in range(31):
        for v in range(1501):
            if x == y == 0:
                continue
            else:
                w1 = (f-(100*a*x + 100*b*y + c*v))//d
#                 w2 = (100*a*x + 100*b*y -c*v)//d
                w3 = ((100*a*x + 100*b*y)*e -c*v*100)//(100*d)
                w = min(w1,w3)
                con1 = 100*(c*v + d*w)/(100*a*x + 100*b*y +c*v +d*w)
                con.append(con1)
                s.append([x,y,v,w])
conm = max(con)
conin =con.index(conm)
t = s[conin]
# print(t)
ans1 = 100*a*t[0] + 100*b*t[1] + c*t[2] + d*t[3]
ans2 = c*t[2] + d*t[3]
print(ans1,ans2)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d,e,f = map(int, input().split())
con = list()
s = list()
for x in range(31):
    for y in range(31):
        for v in range(1501):
            if x == y == 0:
                continue
            else:
                w1 = (f-(100*a*x + 100*b*y + c*v))//d
                w2 = (100*a*x + 100*b*y -c*v)//d
                w3 = ((100*a*x + 100*b*y)*e -c*v*100)//(100*d)
                w = min(w1,w2,w3)
                con1 = 100*(c*v + d*w)/(100*a*x + 100*b*y +c*v +d*w)
                con.append(con1)
                s.append([x,y,v,w])
conm = max(con)
conin =con.index(conm)
t = s[conin]
# print(t)
ans1 = 100*a*t[0] + 100*b*t[1] + c*t[2] + d*t[3]
ans2 = c*t[2] + d*t[3]
print(ans1,ans2)

Submission status: Time Limit Exceeded

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

ans = 0
ideal = e / 100
answer = [100 * a, 0]

for i in range(f // (100 * a) + 1):
    for j in range(f - (100 * a * i) // b + 1):
        for k in range(math.floor(e * (100 * a * i + 100 * b * j) / 100) + 1):
            for l in range(math.floor(e * (100 * a * i + 100 * b * j) / 100) + 1 - k):
                    try:
                        if ideal - ans > ideal - (c * k + d * l) / (100 * a * i + 100 * b * j + c * k + d * l):
                            ans = (c * k + d * l) / (100 * a * i + 100 * b * j + c * k + d * l) 
                            answer = [100 * a * i + 100 * b * j + c * k + d * l, c * k + d * l]
                    except ZeroDivisionError:
                        pass

            
print(answer)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ<=f and s<=e*w/100 and targ!=0 and mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Submission status: Time Limit Exceeded

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

for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                if w+s<=f and s<=e*w/100 and w!=0 and mx<100*s/(w+s):
                    mx=100*s/(w+s)
                    swmx=w+s
                    smx=s
print(swmx,smx)

Submission status: Time Limit Exceeded

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

for i in range(0,31):
    for j in range(0,31):
        for k in range(0,101):
            for l in range(0,101):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                if w+s<=f and s<=e*w/100 and w!=0 and mx<100*s/(w+s):
                    mx=100*s/(w+s)
                    swmx=w+s
                    smx=s
print(swmx,smx)

Submission status: Time Limit Exceeded

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

#memo
list = [0, 0]

#操作1-4
ope1 = 100 * A
ope2 = 100 * B
ope3 = C
ope4 = D
#入れた水、砂糖の総量
w_sum = 0
s_sum = 0
#パーセンテージ
p = 0
#トータル
total = w_sum + s_sum
#砂糖の表示用の変数
s = 0

for i in range(101):
    for j in range(101):
        for k in range(31):
            for l in range(31):
                w_sum = l * ope1 + k * ope2
                s_sum = j * ope3 + i * ope4
                if w_sum != 0 and w_sum + s_sum <= F and s_sum <= E * (l + k) :
                    p_tmp = (s_sum / (w_sum + s_sum)) * 100
                    if p_tmp >= p:
                        p = p_tmp
                        list[0] = w_sum + s_sum
                        list[1] = s_sum
                        if s_sum == E * (l + k):
                            break

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

Submission status: Time Limit Exceeded

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

#memo
list = [0, 0]

#操作1-4
ope1 = 100 * A
ope2 = 100 * B
ope3 = C
ope4 = D
#入れた水、砂糖の総量
w_sum = 0
s_sum = 0
#パーセンテージ
p = 0
#トータル
total = w_sum + s_sum
#砂糖の表示用の変数
s = 0

for i in range(101):
    for j in range(101):
        for k in range(31):
            for l in range(31):
                w_sum = l * ope1 + k * ope2
                s_sum = j * ope3 + i * ope4
                if w_sum != 0 and w_sum + s_sum <= F and s_sum <= E * (l + k) :
                    p_tmp = (s_sum / (w_sum + s_sum)) * 100
                    if p_tmp >= p:
                        p = p_tmp
                        list[0] = w_sum + s_sum
                        list[1] = s_sum

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

Submission status: Time Limit Exceeded

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

#memo
list = [0, 0]

#操作1-4
ope1 = 100 * A
ope2 = 100 * B
ope3 = C
ope4 = D

#入れた水、砂糖の総量
w_sum = 0
s_sum = 0
#パーセンテージ
p = 0
#トータル
total = w_sum + s_sum
#砂糖の表示用の変数
s = 0

for i in range(101):
    for j in range(101):
        for k in range(31):
            for l in range(31):
                w_sum = l * ope1 + k * ope2
                s_sum = j * ope3 + i * ope4
                if w_sum != 0:
                    p_tmp = (s_sum / (w_sum + s_sum)) * 100
                    if w_sum + s_sum <= F and s_sum <= E * (l + k) :
                        if p_tmp >= p:
                            p = p_tmp
                            list[0] = w_sum + s_sum
                            list[1] = s_sum

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

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D,E,F=map(int,input().split())
weight=100*A
suger=0
c=0
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        for k in range((i*A+j*B)*E//C+1):
            for l in range((i*A+j*B)*E//D+1):
                if 100*(i*A+j*B)+k*C+l*D<=F and k*C+l*D<=(i*A+j*B)*E and (i*i+j*j+k*k+l*l)!=0 and (k*C+l*D)/(100*(i*A+j*B)+k*C+l*D)>c:
                    c=(k*C+l*D)/(100*(i*A+j*B)+k*C+l*D)
                    weight=100*(i*A+j*B)+k*C+l*D
                    suger=k*C+l*D


print("{} {}".format(weight,suger))

Submission status: Time Limit Exceeded

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

for i in range(31):
    for j in range(31):
        v = 100*A*i+100*B*j
        if v < F:
            a.append(v)
        else:
            break

for i in range(3000//C+2):
    for j in range(3000//D+2):
        v = C*i+D*j
        if v < F:
            b.append(v)
        else:
            break

a.sort()
b.sort()

c = 0
ans = [0, 0]
for ai in a:
    for bi in b:
        t = ai+bi
        if t > 0 and t <= F and (E*ai//100) >= bi:
            tc = 100*bi/(ai+bi)
            if c < tc:
                c = tc
                ans = [t, bi]
if c == 0:
    while True:
        c = 0
print(*ans)

Submission status: Time Limit Exceeded

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

density = -1
s_water = -1
sugar = -1
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100*A)*a + (100*B)*b
                s = C*c + D*d
                if w == 0:
                    continue
                if w + s > F:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = max(w + s, 100*A)
                        sugar = s
print(s_water, sugar)

Submission status: Time Limit Exceeded

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


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        if 0 < (a*i + b*j)*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    if (c*k + d*l <= (a*i + b*j)*e) and (a*i + b*j)*100+(c*k + d*l) <= f:
                        g = (c*k + d*l)/((a*i + b*j)*100+(c*k + d*l))
                        res.append([g,(a*i + b*j)*100+(c*k + d*l),(c*k + d*l)])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

Submission status: Time Limit Exceeded

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


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        if 0 < (a*i + b*j)*100 < f:
            for k in range(maxcd):
                for l in range(maxcd):
                    if (c*k + d*l <= (a*i + b*j)*e) and (a*i + b*j)*100+(c*k + d*l) <= f:
                        g = (c*k + d*l)/((a*i + b*j)*100+(c*k + d*l))
                        res.append([g,(a*i + b*j)*100+(c*k + d*l),(c*k + d*l)])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

Submission status: Time Limit Exceeded

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

water = set()
sugar = set()

for i in range(F+1):
    for j in range(F+1-A):
        w = (100*A*i) + (100*B*j)
        water.add(w)

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

per = -10000
for w in water:
    for s in sugar:
        ws = w+s
        # 砂糖水の質量合計はFg以下 and 砂糖が溶け残らない
        if (0 < ws <= F) and (s <= w*E // 100):
            if s/(ws) > per:
                per = s/(ws)
                ans = ws, s

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

Submission status: Time Limit Exceeded

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

water = set()
sugar = set()

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

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

per = -10000
for w in water:
    for s in sugar:
        ws = w+s
        # 砂糖水の質量合計はFg以下 and 砂糖が溶け残らない
        if (0 < ws <= F) and (s <= w*E // 100):
            if s/(ws) > per:
                per = s/(ws)
                ans = ws, s

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

Submission status: Time Limit Exceeded

Solution code:
import math

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

highest = 0
sugarwater = 0
maxsugar = 0
amax = math.ceil(f / (100 * a))
bmax = math.ceil(f / (100 * b))
cmax = math.ceil(30 * e / c)
dmax = math.ceil(30 * e / d)
for aa in range(amax):
    for bb in range(bmax):
        water = 100 * (aa * a + bb * b)
        if water == 0 or water > f:
            continue
        for cc in range(cmax):
            for dd in range(dmax):
                sugar = cc * c + dd * d
                if sugar / (water / 100) > e or water + sugar > f:
                    continue
                density = 100 * sugar / (water + sugar)
                if density >= highest:
                    highest = density
                    sugarwater = sugar + water
                    maxsugar = sugar
print(sugarwater, maxsugar)

Submission status: Time Limit Exceeded

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

W = []
S = []

#水の重さのリストW
for i in range(F+1):
    for j in range(F+1):
        x = 100*A*i + 100*B*j
        W.append(x)

#砂糖の重さのリストS
for i in range(F+1):
    for j in range(F+1):
        y = C*i + D*j
        S.append(y)

maxcon = 0
limitcon = 100*E/(100+E)
ans1 = 0
ans2 = 0


for i in range(1,len(W)):
    for j in range(1,len(S)):
        sw = W[i] + S[j]
        con = 100*S[j] / sw
        if (sw <= F) and (con <= limitcon) and (maxcon < con):
            maxcon = con
            ans1 = sw
            ans2 = S[j]



print("%s %s"%(ans1,ans2))

Submission status: Time Limit Exceeded

Solution code:
from operator import itemgetter

A, B, C, D, E, F = list(map(int,input().split()))
X = []
ans = 1000
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                if 100*A*i+100*B*j+C*k+D*l != 0:
                    if 100*A*i+100*B*j+C*k+D*l <= F and (C*k+D*l)/(100*A*i+100*B*j+C*k+D*l) <= E/(100 + E):
                        ans =(E/(100 + E) - (C*k+D*l)/(100*A*i+100*B*j+C*k+D*l))
                        X.append([ans , 100*A*i+100*B*j+C*k+D*l, C*k+D*l])
X = sorted(X,key=itemgetter(0),reverse = False) 

print(X[0][1],X[0][2])

Submission status: Time Limit Exceeded

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

memo = {}
memo.update(density=0, sugerwater=0, suger=0)
for a in range(F//(100*A) + 1):
    for b in range(F//(100*B) + 1):
        for c in range(E*(A*a + B*b)//C + 1):
            for d in range(E*(A*a + B*b)//D + 1):
                # print(100*(A*a + B*b) + C*c + D*d)
                if 100 * (A * a + B * b) + C * c + D * d <= F and C * c + D * d <= E * (A * a + B * b) and (100 * (A * a + B * b) + C * c + D * d) != 0:
                    dens_tmp = 100*(C*c + D*d)/(100*(A*a + B*b) + C*c + D*d)
                    if dens_tmp >= memo['density']:
                        memo.update(density=dens_tmp, sugerwater=100 *
                                    (A * a + B * b) + C * c + D * d, suger=C * c + D * d)

print(memo['sugerwater'], memo['suger'])

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D,E,F=map(int,input().split())
n=F//(100*A)
m=int((F/(100+E))*E/C)
#print(n,m)
a=0
b=0
c=0
for i in range(n+1):
  for j in range(F//(100*B)+1):
    for k in range(m+1):
      for l in range(int((F/(100+E))*E/D)+1):
        if((i>0 or j>0) and (i*A+j*B)*E>=k*C+l*D and 100*(A*i+B*j)+k*C+l*D<=F):
          if((k*C+l*D)/(100*(A*i+B*j)+k*C+l*D)>=c):
            a=100*(A*i+B*j)+k*C+l*D
            b=k*C+l*D
            c=(k*C+l*D)/(100*(A*i+B*j)+k*C+l*D)
            #print(c)
print(a,b)

Submission status: Time Limit Exceeded

Solution code:
A,B,C,D,E,F=map(int,input().split())
n=F//(100*A)
m=int((F/(100+E))*E/C)
#print(n,m)
a=0
b=0
c=0
for i in range(n+1):
  for j in range(n+1):
    for k in range(m+1):
      for l in range(m+1):
        if((i>0 or j>0) and (i*A+j*B)*E>=k*C+l*D and 100*(A*i+B*j)+k*C+l*D<=F):
          if((k*C+l*D)/(100*(A*i+B*j)+k*C+l*D)>=c):
            a=100*(A*i+B*j)+k*C+l*D
            b=k*C+l*D
            c=(k*C+l*D)/(100*(A*i+B*j)+k*C+l*D)
            #print(c)
print(a,b)

Submission status: Time Limit Exceeded

Solution code:
import math
a,b,c,d,e,f = map(int,input().split())
max_sugar = f*e*100/(100+e)
box = {}
for i in range(31):
  for j in range(31):
    water = 100*a*i + 100*b*j
    if water > f:
      break
    sugar_range = int(math.ceil(max_sugar/c))
    for k in range(sugar_range):
      for l in range(sugar_range):
        sugar = c*k + d*l
        if sugar > max_sugar:
          break
        amount = water + sugar
        if amount == 0:
          break
        conc = 100*sugar / amount
        if amount <= f and conc <= e*100/(100+e):
          box[conc] = [amount,sugar]
answer = max(box.items(),key = lambda x:x[0])[1]
print(str(answer[0]) + " " +str(answer[1]))

Submission status: Time Limit Exceeded

Solution code:
import math
a,b,c,d,e,f = map(int,input().split())
max_sugar = f*e*100/(100+e)
box = {}
for i in range(31):
  for j in range(31):
    water = 100*a*i + 100*b*j
    if water > f:
      break
    sugar_range = math.ceil(max_sugar/c)
    for k in range(sugar_range):
      for l in range(sugar_range):
        sugar = c*k + d*l
        if sugar > max_sugar:
          break
        amount = water + sugar
        if amount == 0:
          break
        conc = 100*sugar / amount
        if amount <= f and conc <= e*100/(100+e):
          box[conc] = [amount,sugar]
answer = max(box.items(),key = lambda x:x[0])[1]
print(str(answer[0]) + " " +str(answer[1]))

Submission status: Time Limit Exceeded

Solution code:
import math
a,b,c,d,e,f = map(int,input().split())
max_sugar = f*e*100/(100+e)
box = {}
for i in range(31):
  for j in range(31):
    water = 100*a*i + 100*b*j
    if water > f:
      break
    for k in range(math.ceil(max_sugar/c)):
      for l in range(math.ceil(max_sugar/d)):
        sugar = c*k + d*l
        if sugar > max_sugar:
          break
        amount = water + sugar
        if amount == 0:
          break
        conc = 100*sugar / amount
        if amount <= f and conc <= e*100/(100+e):
          box[conc] = [amount,sugar]
answer = max(box.items(),key = lambda x:x[0])[1]
print(str(answer[0]) + " " +str(answer[1]))

Submission status: Time Limit Exceeded

Solution code:
import math
a,b,c,d,e,f = map(int,input().split())
max_sugar = f*e*100/(100+e)
box = {}
for i in range(31):
  for j in range(31):
    water = 100*a*i + 100*b*j
    if water > f:
      break
    sugar_range = math.ceil(max_sugar/c)
    for k in range(sugar_range):
      for l in range(sugar_range):
        sugar = c*k + d*l
        if sugar > max_sugar:
          break
        amount = water + sugar
        if amount == 0:
          break
        conc = 100*sugar / amount
        if amount <= f and conc <= e*100/(100+e):
          box[conc] = [amount,sugar]
new_box = sorted(box.items(),reverse = True)
print(str(new_box[0][1][0]) + " " +str(new_box[0][1][1]))

Submission status: Time Limit Exceeded

Solution code:
import math
a,b,c,d,e,f = map(int,input().split())
max_sugar = f*e*100/(100+e)
box = {}
for i in range(31):
  for j in range(31):
    water = 100*a*i + 100*b*j
    if water > f:
      break
    for k in range(math.ceil(max_sugar/c)):
      for l in range(math.ceil(max_sugar/d)):
        sugar = c*k + d*l
        if sugar > max_sugar:
          break
        amount = water + sugar
        if amount == 0:
          break
        conc = 100*sugar / amount
        if amount <= f and conc <= e*100/(100+e):
          box[conc] = [amount,sugar]
new_box = sorted(box.items(),reverse = True)
print(str(new_box[0][1][0]) + " " +str(new_box[0][1][1]))