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:
#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 = min(water_volume * max_density, max_volume - water_volume * 100)
    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: Accepted

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

Solution code:
A,B,C,D,E,F=map(int,input().split())
x=1
y=-1
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: Accepted

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 = 100 * a
    for i in range(31):
        for j in range(31):
            water = i * 100 * a + j * 100 * b
            for k in range(3001):
                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: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
print(*max(
  [[s/(s+w),s+w,s]
    for t in range(0,f+1,a*100)
    for w in range(t,f+1,b*100)
    if w>0
    for m in [min(f-w,w*e//100)+1]
    for u in range(0,m,c)
    for s in range(u,m,d)
  ])[1:])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
q=[]
for t in range(0,f+1,a*100):
  for w in range(t,f+1,b*100):
    if w>0:
      m=min(f-w,w*e//100)+1
      for u in range(0,m,c):
        for s in range(u,m,d):
          v=s+w
          q.append([s/v,v,s])
print(*max(q)[1:])

Submission status: Accepted

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 = -1
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: Accepted

Solution code:
# -*- coding: utf-8 -*-
A, B, C, D, E, F = tuple(map(int, input().split()))
A, B = 100*A, 100*B
waters = set([a+b for b in range(0, F+1, B) for a in range(0, F+1, A) if a+b <= F])

res_water = min(A, B)
res_sugar = 0
max_ratio = 0

for w in sorted(waters):
    sugars = [c+d for c in range(0, int(w//100)*E+1, C)
                         for d in range(0, int(w//100)*E+1, D) 
                             if (c+d+w <= F) and (c+d <= int(w/100)*E)]
    sugar = max(sugars)
    #print(sugars)
    if w+sugar==0:
        continue
    if 100*sugar / (w+sugar) > max_ratio:
        max_ratio = 100*sugar / (w+sugar)
        res_water = w
        res_sugar = sugar
print("{} {}".format(res_water+res_sugar, res_sugar))

Submission status: Accepted

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
    	
if maxtotal == 0:
	maxtotal = A*100
print(maxtotal,end=" ")
print(maxsugar)

Submission status: Accepted

Solution code:
def get_set(_max, a, b):
    ans = set()
    g = _max // a
    for h in range(g + 1):
        k = (_max - a * h) // b
        for l in range(k + 1):
            ans.add(a * h + b * l)
    ans.discard(0)
    return ans


a, b, c, d, e, f = map(int, input().split())
ab = get_set(f, a * 100, b * 100)
max_l, max_s, max_r = 0, 0, 0
for n in ab:
    o = min(f - n, n * e // 100)
    if o / (n + o) < max_r:
        continue
    tmp_max = max(get_set(o, c, d), default=0)
    tmp_rate = tmp_max / (n + tmp_max)
    if tmp_rate >= max_r:
        max_l = n + tmp_max
        max_s = tmp_max
        max_r = tmp_rate

print(max_l, max_s)

Submission status: Accepted

Solution code:
import math

m = [0,0,-1]
mem = [[-1 for i in range(3200)] for j in range(3200)]

def cal(a,b):
    try:
        return 100 * b / (a + b)
    except:
        return 0

def dfs(water,suger,p,nums):
    global m
    global mem
    
    if water+suger > nums[5]: pass
    elif mem[water][suger] == -1: 
        mem[water][suger] = cal(water,suger)
    else:
        return mem[water][suger]


    if water != 0 and ((suger / water > nums[4] / 100 ) or (water + suger > nums[5])):
        return p

    if m[2] < cal(water,suger):
        m = [water,suger,cal(water,suger)]

    ans = max(
            dfs(water + nums[0] * 100, suger, cal(water,suger), nums),
            dfs(water + nums[1] * 100, suger, cal(water,suger), nums),
            dfs(water, suger + nums[2], cal(water,suger),nums),
            dfs(water, suger + nums[3], cal(water,suger),nums)
            )
    return ans


nums = [int(x) for x in input().split()]
A,B = nums[0],nums[1]
dfs(nums[0]*100,0,0,nums)
dfs(nums[1]*100,0,0,nums)
print(str(m[0]+m[1]) + " " + str(m[1]))

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy

from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

class water_node():
    def is_meltable(self):
        if self.sugar <= self.water * self.meltable/100:
            return True
        return False
    def __init__(self, water, sugar, meltable):
        self.water = water
        self.sugar = sugar
        self.mass = water + sugar
        self.meltable = meltable
        self.is_all_melt = self.is_meltable()
        if self.sugar + self.water > 0:
            self.concentration = self.sugar * 100.0 /float(self.sugar + self.water)
        else:
            self.concentration = -1.0


    def __eq__(self,other):
        return (self.water  == other.water) and (self.sugar  == other.sugar)

    def __hash__(self):

        return hash (self.water + self.sugar* 10000)


def BFS(A, B, C, D, E, F):
    n = water_node(0, 0, E)
    done_set = set([n])
    node_list = deque([n])
    max_concentration_node = n
    while len(node_list) > 0:
        n = node_list.popleft()
        #ope1
        new_node_list = []
        new_node_list.append(water_node(n.water + A * 100, n.sugar, E))
        new_node_list.append(water_node(n.water + B * 100, n.sugar, E))
        new_node_list.append(water_node(n.water, n.sugar + C, E))
        new_node_list.append(water_node(n.water, n.sugar + D, E))
        for new_node in new_node_list:
            if new_node.mass <= F:
                if new_node not in done_set:
                    done_set.add(new_node)
                    node_list.append(new_node)
                    if new_node.is_all_melt == True and new_node.concentration > max_concentration_node.concentration:
                        max_concentration_node = new_node
    return max_concentration_node


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [A, B, C, D, E, F] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2]), int(input_raw[3]), int(input_raw[4]), int(input_raw[5])]
    max_c = BFS(A, B, C, D, E, F)
    print int(max_c.mass), int(max_c.sugar)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

def solve():
    a, b, c, d, e, f = map(int, input().split())
    water_pair = []
    a_list = [a * i * 100 for i in range(f//(a * 100) + 1)]
    b_list = [b * i * 100 for i in range(f//(b * 100) + 1)]
    for elem in list(itertools.permutations(a_list + b_list, 2)):
        water_pair.append(elem[0] + elem[1])
    
    solt_max = int(f * ((100 * e) / (100 + e) / 100))
    water_pair = [i for i in set(water_pair) if f > i > 0]
    solt_pair = []
    c_list = [c * i for i in range(solt_max//c + 1)]
    d_list = [d * i for i in range(solt_max//b + 1)]
    for elem in list(itertools.permutations(c_list + d_list, 2)):
        solt_pair.append(elem[0] + elem[1])
    solt_pair = [i for i in set(solt_pair) if solt_max >= i]
    
    water_pair.sort()
    solt_pair.sort()
    max_pair = 0
    ans = [a * 100, 0]
    for water in water_pair:
        limit_solt = e * (water // 100)
        for solt in solt_pair:
            if solt > limit_solt:
                break
            if water + solt > f:
                break
            if (100 * solt) / (water + solt) > max_pair:
                max_pair = (100 * solt) / (water + solt)
                ans = [water + solt, solt]
    print(ans[0], ans[1])
    

if __name__=="__main__":
    solve()

Submission status: Accepted

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

A,B,C,D,E,F = map(int, input().split())
A *= 100
B *= 100
E = round(E/(100+E), 8)

# binary search
def check(i, total, sugar):
	exp = (sugar + D*i) / (total + D*i)
	return total + D*i <= F and round(exp, 8) <= E
	

def binarySearch(small, big, total, sugar):
	mid = (big + small) // 2
	if big - small <= 1:
		if check(big, total, sugar): return big
		else:          return small
	else:
		if check(mid, total, sugar):
			return binarySearch(mid, big, total, sugar)
		else:
			return binarySearch(small, mid, total, sugar)

noudo = 0
ans = (0, 0)
for a in range(31):
	for b in range(31):
		for c in range(3001):
			water = a*A + b*B
			sugar = c * C
			total = water + sugar
			if not (a, b) == (0, 0):
				if total <= F and round(sugar / total, 8) <= E:
					d = binarySearch(0, 3000, total, sugar)
					tmp = (sugar + D*d) / (total + D*d)
					if round(tmp, 8) > noudo:
						noudo = round(tmp, 8)
						ans = (total+D*d, sugar+D*d)

if ans[0] == 0:
	print(A, 0)
else:
	print(ans[0], ans[1])

Submission status: Accepted

Solution code:

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

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


smax=0
wmax=100*a
maxnoudo=0

for na in range(int(f/(100*a))+1):
    for nb in range(int(f/(100*b))+1):
        for nc in range(int(f/c)+2):
            for nd in range(int(f/d)+2):
                W=na*100*a+nb*100*b
                S=nc*c+nd*d


                if W+S>f:
                    break

                if W+S==0:
                    continue

                noudo=S/(W+S)
                #print(noudo,S,W,f,e)
                #print("aaa")
                if noudo>e/(100+e):
                    break

                #print(na,nb,nc,nd)
                if maxnoudo<noudo:
                    maxnoudo=noudo
                    smax=S
                    wmax=W
                    #input()


print(smax+wmax,smax)

Submission status: Accepted

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

ans = [100 * a, 0]
for ka in range(f // (100 * a) + 1):
    for kb in range(f // (100 * b) + 1):
        for kc in range(f // c + 1):
            l = 0
            r = f // d + 1
            while 1 < r - l:
                m = (l + r) // 2
                sg = kc * c + m * d
                sw = 100 * ka * a + 100 * kb * b + sg
                if f < sw:
                    r = m
                    continue
                if (100 + e) * sg <= sw * e:
                    l = m
                else:
                    r = m
            kd = l
            sg = kc * c + kd * d
            sw = 100 * ka * a + 100 * kb * b + sg
            if sw <= f and (100 + e) * sg <= sw * e and ans[1] * sw < ans[0] * sg:
                ans = [sw, sg]
print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import heapq
import math

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin 
a,b,c,d,e,f = map(int,stdin.readline().split())
fir = [0] * (f+1)
sec = [0] * (f+1)
# first check what water and sugar amounts are possible
fir[0] = sec[0] = 1 
for i in xrange(f+1):
    nex = i + a*100 
    if nex<=f and fir[i]:
        fir[nex] = 1 
    nex = i + c 
    if  nex<=f and sec[i]:
        sec[nex] = 1 
    nex = i + b*100 
    if nex<=f and fir[i]:
        fir[nex] = 1 
    nex = i +  d 
    if  nex<=f and sec[i]:
        sec[nex] = 1 
valid = []
for i in xrange(1,f+1):
    for j in xrange(0,f+1):
        # taking i water and j sugar
        if fir[i] and sec[j]:
            if i +  j<=f:
                if e*i >= 100*j:
                    valid.append((i,j))
num = -1
den = 1*100
for y,x in valid:
    if x*den > y*num:
        num = x
        den = y
print num+den,num

Submission status: Accepted

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

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

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

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

ans = (0, 0, 0)

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

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

Submission status: Accepted

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


from itertools import product
water = set()

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

water = sorted(water)

salt = set()

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

salt = sorted(salt)

from bisect import bisect_left



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

print(bs+100*bw,bs)

Submission status: Accepted

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

ans_water = None
ans_sugar = None

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

print (ans_water + ans_sugar), ans_sugar

Submission status: Accepted

Solution code:
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


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


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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

A_limit = F // (100*A)

max_density = 0.0
max_suger = 0
max_total = 0

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d,e,f = LI()
    f += 1
    a *= 100
    b *= 100
    m = [0] * f
    s = [0] * f
    m[0] = 1
    s[0] = 1
    for i in range(f-a):
        if m[i] == 1:
            m[i+a] = 1
    for i in range(f-b):
        if m[i] == 1:
            m[i+b] = 1

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

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

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


print(main())

Submission status: Accepted

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

bestWater = -1
bestSugar = -1
bestDensity = -1
possibleWater.remove(0)
for w in possibleWater:
    for s in possibleSugar:
        #print(w,s)
        if w/100 * E < s:
            #print("too much sugar")
            continue
        if w+s>F:
            #print("too much mass")
            continue
        density = 100*s/(w+s)
        if density>bestDensity:
            bestDensity = density
            bestWater = w
            bestSugar = s

print(bestWater+bestSugar,bestSugar)

Submission status: Runtime Error

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

for i in range(31):
    for j in range(31):
        if i+j==0:continue
        for k in range(31):
            for l in range(31):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= 100*sugar/(water+sugar)
                if e<= pp and ans<pp:
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

Submission status: Runtime Error

Solution code:
a,b,c,d,e,mv=map(int,input().split())
ans=0
for i in range(31):
    for j in range(31):
        for k in range(31):
            for l in range(31):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= 100*sugar/(water+sugar)
                if e<= pp and ans<pp:
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

Submission status: Runtime Error

Solution code:
a,b,c,d,e,f=map(int,input().split())
dp=[0]*(f+1)
w=[]
s=[]
for i in range(f+1):
  if i%(a*100)==0:dp[i]=i
  if i%(b*100)==0:dp[i]=i
  if i>a*100 and dp[i-a*100]:dp[i]=i
  if i>a*100 and dp[i-b*100]:dp[i]=i
for i in dp:
  if i:w.append(i)
m=w[-1]*e//100+1
dp=[0]*(m)
for i in range(m):
  if i%c==0:dp[i]=i
  if i%d==0:dp[i]=i
  if i>c and dp[i-c]:dp[i]=i
  if i>d and dp[i-d]:dp[i]=i
for i in dp:
  if i: s.append(i)
g=0
for i in w:
  for j in s:
    if i+j<=f and g<j/(i+j)<=e/(100+e):
      g=j/(i+j)
      ans=(i+j,j)
print(*ans)

Submission status: Runtime Error

Solution code:
import bisect
a, b, c, d, e, f = map(int, input().split())
a = a * 100
b = b * 100
g = f * e // 100
wtr = [0] * f
sgr = [0] * g
wtr[0] = 1
sgr[0] = 1
wtr_l = []
sgr_l = []


def comb(lmt, tgt, lis):
    for i in range(lmt - tgt):
        if lis[i] != 0:
            lis[i + tgt] = 1


comb(f, a, wtr)
comb(f, b, wtr)
comb(g, c, sgr)
comb(g, d, sgr)

for i, w in enumerate(wtr):
    if i == 0:
        continue
    elif w == 1:
        wtr_l.append(i)

for j, s in enumerate(sgr):
    if j == 0:
        continue
    elif s == 1:
        sgr_l.append(j)

res = 0
ans = []
for wt in wtr_l:
    pct = min(f - wt, wt * e // 100)
    sid = bisect.bisect_left(sgr_l, pct)
    if pct in sgr_l:
        sgr_max = sgr_l[sid]
    else:
        sgr_max = sgr_l[sid - 1]
    pct_max = 100 * sgr_max / (wt + sgr_max)
    if pct_max > res:
        res = pct_max
        ans.append((wt + sgr_max, sgr_max))
print(*ans[-1])

Submission status: Runtime Error

Solution code:
from itertools import product

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

lima = [100 * a * i for i in range(f // (100 * a) + 1)]
limb = [100 * b * i for i in range(f // (100 * b) + 1)]
setw = set([i + j for i, j in product(lima, limb) if 0 < i + j <= f])
limc = [c * i for i in range(f // c + 1)]
limd = [d * i for i in range(f // d + 1)]
sets = set([i + j for i, j in product(limc, limd) if 0 < i + j <= f])

cnt = 0
for w in setw:
    for s in sets:
        if (cnt <= 100 * s / w <= e) and (s + w <= f):
            cnt = 100 * s / w
            ans = s + w, s
else:
    print(*ans)