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:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume * 100 <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, 1 + curr_optimal_sugar // spoon1):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((max_volume - water_volume * 100 - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density > global_dencity:
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Wrong Answer

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

a = int(F/A)
b = int(F/B)

hoge = 0

water = [[0 for i in range(a+1)]for i in range(b+1)]
sugar = [[0 for i in range(a+1)]for i in range(b+1)]

noudo = [[0 for i in range(a+1)]for i in range(b+1)]

for i in range(a+1):
    for j in range(b+1):
        if A*i+B*j < F:
            water[j][i] = A*i+B*j
       


        c = int(E*water[j][i]/(100*C))
        d = int(E*water[j][i]/(100*D))
        for k in range(c+1):
            for m in range(d+1):
                if C*k+D*m <= F-water[j][i]  and C*k+D*m < E*water[j][i]/100:
                    sugar[j][i] = max(sugar[j][i],C*k+D*m)

for i in range(a+1):
    for j in range(b+1):
        if water[j][i] != 0 and sugar[j][i] != 0:
            noudo[j][i] = sugar[j][i]/(water[j][i]+sugar[j][i])
        if hoge <= noudo[j][i]:
            res_i = i
            res_j = j
            hoge = noudo[j][i]

print(water[res_j][res_i]+sugar[res_j][res_i],sugar[res_j][res_i])

Submission status: Wrong Answer

Solution code:
A,B,C,D,E,F=map(int,input().split())
x=1
y=0
for a in range(0,F+1,100*A):
    for b in range(0,F-a+1,100*B):
        m=min(F-a-b,(a+b)*E//100)
        if a+b==0:
            continue
        for c in range(0,m+1,C):
            for d in range(0,m-c+1,D):
                if y/x<(c+d)/(a+b):
                    x=a+b
                    y=c+d
print(x+y,y)

Submission status: Wrong Answer

Solution code:
A,B,C,D,E,F=map(int,input().split())
x=1
y=0
for a in range(0,F+1,100*A):
    for b in range(0,F-a+1,100*B):
        m=min(F-a-b,(a+b)*E//100)
        if a+b==0:
            continue
        for c in range(0,m+1,C):
            d=(m-c)//D*D
            if y/x<(c+d)/(a+b):
                x=a+b
                y=c+d
print(x+y,y)

Submission status: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() == 'N551J':
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    a, b, c, d, e, f = read_int_list()
    best_sugar = 0
    best_total = a
    i = 0
    # for i in range(31):
    while 100 * i * a <= f:
        j = 0
        # for j in range(31):
        while 100 * i * a + 100 * j * b <= f:
            water = i * 100 * a + j * 100 * b
            k = 0
            # for k in range(3001):
            while water + k * c <=f:
                if water + k * c <= f and k * c * 100 <= water * e:
                    l1 = int((f - water - k * c) / d)
                    l2 = int((water * e // 100 - k * c) / d)
                    l = min(l1, l2)
                    if (i, j, k, l) != (0, 0, 0, 0):
                        sugar = k * c + l * d
                        total = water + sugar
                        density = sugar / total
                        best_density = best_sugar / best_total
                        if density > best_density:
                            best_sugar = sugar
                            best_total = total
                k += 1
            j += 1
        i += 1
    return best_total, best_sugar


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() == 'N551J':
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    a, b, c, d, e, f = read_int_list()
    best_sugar = 0
    best_total = a
    for i in range(31):
        for j in range(31):
                for k in range(3001):
                    water = i * 100 * a + j * 100 * b
                    if water + k * c <= f and k * c * 100 <= water * e:
                        l1 = int((f - water - k * c) / d)
                        l2 = int((water * e // 100 - k * c) / d)
                        l = min(l1, l2)
                        if (i, j, k, l) != (0, 0, 0, 0):
                            sugar = k * c + l * d
                            total = water + sugar
                            density = sugar / total
                            best_density = best_sugar / best_total
                            if density > best_density:
                                best_sugar = sugar
                                best_total = total
    return best_total, best_sugar


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() == 'N551J':
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    a, b, c, d, e, f = read_int_list()
    best_sugar = 0
    best_total = a
    for i in range(31):
        for j in range(31):
            if (i, j) != (0, 0):
                for k in range(3001):
                    water = i * 100 * a + j * 100 * b
                    if water + k * c <= f and k * c * 100 <= water * e:
                        l1 = int((f - water - k * c) / d)
                        l2 = int((water * e // 100 - k * c) / d)
                        l = min(l1, l2)
                        sugar = k * c + l * d
                        total = water + sugar
                        density = sugar / total
                        best_density = best_sugar / best_total
                        if density > best_density:
                            best_sugar = sugar
                            best_total = total
    return best_total, best_sugar


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() == 'N551J':
    sys.stdin = open('a1.in')


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


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    a, b, c, d, e, f = read_int_list()
    best_sugar = 0
    best_total = a
    for i in range(31):
        for j in range(31):
            if (i, j) != (0, 0):
                for k in range(3001):
                    water = i * 100 * a + j * 100 * b
                    if water + k * c <= f and k * c * 100 <= water * e:
                        l1 = int((f - water - k * c) / d)
                        l2 = int((water * e / 100 - k * c) / d)
                        l = min(l1, l2)
                        sugar = k * c + l * d
                        total = water + sugar
                        density = sugar / total
                        best_density = best_sugar / best_total
                        if density > best_density:
                            best_sugar = sugar
                            best_total = total
    return best_total, best_sugar


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a,b,c,d,e,f=map(int,input().split())
x=[]
y=[]
for i in range(f):
	for j in range(f):
		sm1=100*i*a+100*j*b
		if sm1 < f and sm1 > 0:
			x.append(sm1)
for i in range(f):
	for j in range(f):
		sm2=c*i+j*d
		if sm2 < f and sm2 > 0:
			y.append(sm2)
mx=0
ans1=0
ans2=0
for w in x:
	for s in y:
		su=w//100
		if s*su <=e*su:
			s*=su
			if w+s <= f:
				den=(100*s)//(w+s)
				if den > mx:
					mx=den
					ans1=w+s
					ans2=s

print(ans1,ans2)

Submission status: Wrong Answer

Solution code:
A, B, C, D, E, F = map(int, raw_input().split())
water_list = set()
for i in range(F//(A*100)+1):
    for j in range((F-i*A*100)//(B*100)+1):
        if i*100*A+j*100*B <= F:
            water_list.add(i*A*100+j*B*100)
water_list.discard(0)
max_ratio = 0
suger, water = 0, 0
for w in water_list:
    for c in range((F-w)//C + 1):
        for d in range((F-w-c*C)//D+1):
            s = c*C+d*D
            if w + s <= F and s*1. / w * 100 <= E and max_ratio < s*100./(w+s):
                max_ratio = s*100. / (w+s)
                water = w
                suger = s
print water+suger, suger

Submission status: Wrong Answer

Solution code:
A, B, C, D, E, F = map(int, raw_input().split())
water_list = set()
for i in range(F//(A*100)+1):
    for j in range((F-i*100)//(B*100)+1):
        if i*100*A+j*100*B < F:
            water_list.add(i*A*100+j*B*100)
water_list.discard(0)
max_ratio = 0
suger, water = 0, 0
for w in water_list:
    for c in range((F-w)//C + 1):
        for d in range((F-w-c*C)//D+1):
            s = c*C+d*D
            if w + s <= F and s*1. / w * 100 <= E and max_ratio < s*100./(w+s):
                max_ratio = s*100. / (w+s)
                water = w
                suger = s
print water+suger, suger

Submission status: Wrong Answer

Solution code:
A, B, C, D, E, F = map(int, raw_input().split())
water_list = set()
for i in range(F//(A*100)+1):
    for j in range((F-i*100)//(B*100)+1):
        if i*100*A+j*100*B < F:
            water_list.add(i*A*100+j*B*100)
water_list.discard(0)
max_ratio = 0
suger, water = 0, 0
for w in water_list:
    for c in range(0, F-w+1, C):
        for d in range(0, F-w-c+1, D):
            if w + c + d <= F and (c+d)*1. / w * 100 <= E and max_ratio < (c+d)*100./(w+c+d):
                max_ratio = (c+d)*100. / (w+c+d)
                water = w
                suger = c+d
print water+suger, suger

Submission status: Wrong Answer

Solution code:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume * 100 <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, 1 + curr_optimal_sugar // spoon1):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density > global_dencity:
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Wrong Answer

Solution code:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, 1 + curr_optimal_sugar // spoon1):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density >= global_dencity:
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Wrong Answer

Solution code:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, curr_optimal_sugar // spoon1):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density >= global_dencity:
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Wrong Answer

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = 0
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        con = mem[(water_sum, suger_sum)]
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con
        return max_con
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        con = dps(mem, water_sum, suger_sum + s)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum + s
            max_con = con

    for w in water:
        if water_sum + suger_sum + w > F:
            continue
        con = dps(mem, water_sum + w, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum + w, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        con = dps(mem, water_sum, suger_sum + s)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum + s
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Submission status: Wrong Answer

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = 0
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        con = mem[(water_sum, suger_sum)]
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con
        return max_con
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        con = dps(mem, water_sum, suger_sum + s)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum + s
            max_con = con

    for w in water:
        if water_sum + suger_sum + w > F:
            continue
        con = dps(mem, water_sum + w, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum + w, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D,E,F = list(map(int, input().split()))
maxdensity=0;
maxtotal=0;
maxsugar=0;

listwater = list()
for nA in range(30):
    for nB in range(15):
    	water = 100*(nA*A+nB*B)
    	if water == 0:
    		continue
    	if water <= F and (not water in listwater):
    		listwater.append(water)

listsugar = list()
for nC in range(3000):
    for nD in range(1500):
    	sugar = (nC*C+nD*D)
    	if sugar <= F/2 and (not sugar in listsugar):
    		listsugar.append(sugar)

listsugar.sort()
listwater.sort()

for i in range(len(listsugar)):
    for j in range(len(listwater)):
    	total = listsugar[i] + listwater[j]
    	sugar = listsugar[i]
    	if total == 0:
    		continue
    	if total <= F and sugar*100 <= E*(total-sugar):
    		if maxdensity*total < sugar:
    			maxdensity = float(sugar)/float(total)
    			maxtotal = total
    			maxsugar = sugar
    					
print(maxtotal,end=" ")
print(maxsugar)

Submission status: Wrong Answer

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = 0
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        return max(max_con, mem[(water_sum, suger_sum)])
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        con = dps(mem, water_sum, suger_sum + s)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum + s
            max_con = con

    for w in water:
        if water_sum + suger_sum + w > F:
            continue
        con = dps(mem, water_sum + w, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum + w, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D,E,F = list(map(int, input().split()))
maxdensity=0;
maxtotal=0;
maxsugar=0;

listwater = list()
for nA in range(30):
	for nB in range(15):
		water = 100*(nA*A+nB*B)
		if water == 0:
			continue
		if water <= F and (not water in listwater):
			listwater.append(water)

listsugar = list()
for nC in range(3000):
	for nD in range(1500):
		sugar = (nC*C+nD*D)
		if sugar <= F/2 and (not sugar in listsugar):
			listsugar.append(sugar)

listsugar.sort()
listwater.sort()

for i in range(len(listsugar)):
	for j in range(len(listwater)):
		total = listsugar[i] + listwater[j]
		sugar = listsugar[i]
		if total == 0:
			continue
		if total <= F and sugar*100 <= E*(total-sugar):
			if maxdensity*total < sugar:
				maxdensity = float(sugar)/float(total)
				maxtotal = total
				maxsugar = sugar
		
					
						
print(maxtotal,end=" ")
print(maxsugar)

Submission status: Wrong Answer

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = 0
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        return max(max_con, mem[(water_sum, suger_sum)])
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s > F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        suger_sum += s
        con = dps(mem, water_sum, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for w in water:
        if water_sum + suger_sum + w > F:
            continue
        water_sum += w
        con = dps(mem, water_sum, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Submission status: Wrong Answer

Solution code:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, 100):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density >= global_dencity:
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Wrong Answer

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = 0
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        return max(max_con, mem[(water_sum, suger_sum)])
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s >= F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        suger_sum += s
        con = dps(mem, water_sum, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for w in water:
        if water_sum + suger_sum + w >= F:
            continue
        water_sum += w
        con = dps(mem, water_sum, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)

Submission status: Wrong Answer

Solution code:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = cup1            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, 100):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif (curr_sugar / water_volume) >= (global_optimal_sugar / global_optimal_water):
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Wrong Answer

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

water = [100 * A, 100 * B]
suger = [C, D]

mem = {}
water_ans = 0
suger_ans = 0
max_con = 0
def dps(mem, water_sum, suger_sum):
    global water_ans
    global suger_ans
    global max_con
    if (water_sum, suger_sum) in mem:
        return mem[(water_sum, suger_sum)]
    if water_sum + suger_sum == 0:
        mem[(water_sum, suger_sum)] = 0
    else:
        con = (100 * suger_sum) / (water_sum + suger_sum)
        mem[(water_sum, suger_sum)] = con
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for s in suger:
        if water_sum + suger_sum + s >= F:
            continue
        if suger_sum + s > water_sum / 100 * E:
            continue
        suger_sum += s
        con = dps(mem, water_sum, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    for w in water:
        if water_sum + suger_sum + w >= F:
            continue
        water_sum += w
        con = dps(mem, water_sum, suger_sum)
        if max_con < con:
            water_ans, suger_ans = water_sum, suger_sum
            max_con = con

    return max_con 

ans = dps(mem, 0, 0)
print(water_ans + suger_ans, suger_ans)