Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Snuke will make sugar water with the highest possible density.

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

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

Constraints

1 \leq A < B \leq 30

1 \leq C < D \leq 30

1 \leq E \leq 100

100A \leq F \leq 3 000

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

Inputs

Input is given from Standard Input in the following format:

A B C D E F

Outputs

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

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10

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

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

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

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

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100

There are other acceptable outputs, such as:

400 200

However, the output below is not acceptable:

300 150

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

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934



Sample input:
1 2 10 20 15 200


Sample output:
110 10

Submission status: Accepted

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

a *= 100
b *= 100

#取りうる水の値をリスト化
wat = 0
wat_list = []
for i in range(f//a+1):
    for j in range(f//b+1):
        wat = a*i+b*j
        if 0 < wat <= f:
            wat_list.append(wat)

#水の量に対して砂糖の量をリストで計算
sug = 0
sug_max = 0
sug_list = []
conc_list = []
sug_wat_list = []
for k in wat_list:
    sug_max = k//100 * e
    for l in range(sug_max // c + 1):
        for m in range(sug_max //d + 1):
            sug = c*l+d*m
            if 0<= sug <= sug_max and k+sug <= f: #溶けること＋溢れないこと
                sug_list.append(sug)
                conc_list.append(sug/(sug+k)*100)
                sug_wat_list.append(sug+ k)

idx = conc_list.index(max(conc_list))
print(sug_wat_list[idx], sug_list[idx])

Submission status: Accepted

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

anum = f // (100*a)
bnum = f // (100*b)

cp = 0
for ca in range(anum+1):
    for cb in range(bnum+1):
        water = (a*ca + b*cb)*100
        if water > f:
            continue
        cnum = e * (a*ca+b*cb) // c
        dnum = e * (a*ca+b*cb) // d
        for cc in range(cnum+1):
            for cd in range(dnum+1):
                sugar = c*cc + d*cd
                # print(ca, cb, cc, cd, water, sugar)
                if water + sugar <= 0 or water + sugar > f or sugar > e * (a*ca+b*cb):
                    continue
                p = 100 * sugar / (water + sugar)
                if p >= cp:
                    cp = p
                    ans = [str(water + sugar), str(sugar)]
print(' '.join(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

x = f // (100*a)
y = f // (100*b)

max_ = -1
max__ = 1
for i in range(x + 1):
    for j in range(y + 1):
        E = min((a*i + b*j) * e, f - (100*a*i + 100*b*j))
        min_ = inf
        for k in range(E // c + 1):
            for l in range(E // d + 1):
                if c*k + d*l > E:
                    continue
                min_ = min(min_, E - c*k - d*l)
        E -= min_
        if max_ * (a*i + b*j) < E * max__:
            max_ = E
            max__ = a*i + b*j
            ans1 = (a*i + b*j) * 100 + E
            ans2 = E
print(ans1, ans2)

Submission status: Accepted

Solution code:
import sys

a, b, c, d, e, f = map(int, input().split())
a *= 100
b *= 100
thr = e / (e + 100) * 100

water = set()
sugar = set()

for i in range(f // a + 1):
    for j in range((f - i * a) // b + 1):
        if i + j >= 1:
            water.add(i * a + j * b)

for i in range(f // c + 1):
    for j in range((f - i * c) // d + 1):
        sugar.add(i * c + j * d)

water = list(water)
sugar = list(sugar)
water.sort()
sugar.sort()

result = []
for w in water:
    for s in sugar:
        dens = s / (w + s) * 100
        if w + s > f or dens > thr:
            continue
        else:
            result.append((dens, w + s, s))

if len(result) == 0:
    print(-1)
    sys.exit()
else:
    result.sort(reverse=True)
    print(result[0][1], result[0][2])

Submission status: Accepted

Solution code:
import sys
 
A, B, C, D, E, F = map(int, sys.stdin.readline().split())
 
max_a = (F - 1) // (100 * A) + 1
max_b = (F - 1) // (100 * B) + 1
 
max_rate = 0
ans_water = 0
ans_sugar = 0
for a in range(max_a + 1):
    for b in range(max_b + 1):
        water = 100 * A * a + 100 * B * b
        if water >= F:
            break
 
        max_sugar = min(F - water, water // 100 * E)
        # print("max_sugar", max_sugar)
        max_c = (max_sugar - 1) // C + 1
        max_d = (max_sugar - 1) // D + 1
        for c in range(max_c + 1):
            for d in range(max_d + 1):
                sugar = C * c + D * d
                if sugar > max_sugar or sugar + water > F:
                    break
 
                if sugar * (ans_water + ans_sugar) >= ans_sugar * (water + sugar):
                    ans_water = water
                    ans_sugar = sugar
 
print(ans_water + ans_sugar, ans_sugar)

Submission status: Accepted

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

Submission status: Accepted

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

i = 0
while True:
    j = 0
    if 100*a*i + 100*b*j > f:
        break
    while True:
        if 100*a*i + 100*b*j <= f:
            water.add(100*a*i + 100*b*j)
        else:
            break
        j += 1
    i += 1

i = 0
while True:
    j = 0
    if c*i + d*j > f:
        break
    while True:
        if c*i + d*j <= f:
            sugar.add(c*i + d*j)
        else:
            break
        j += 1
    i += 1

# print(water, sugar)
nodo = 0.0
ans = [0, 0]
for w in water:
    for s in sugar:
        if w != 0:
            if e/100 >= s/w and f >= s+w:
                if nodo <= s/w:
                    nodo = s/w
                    ans = s+w, s

print(*ans)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1
 
for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar
 
print(ans0, ans1)

Submission status: Accepted

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

for x in range(F//(100*A)+1):
    for y in range((F-100*A*x)//(100*B)+1):
        if x == y == 0: continue
        sugarMAX = (A*x+B*y)*E
        M = F-100*A*x-100*B*y
        water = 100*A*x+100*B*y
        for z in range(M//C+1):
            for w in range((M-C*z)//D+1):
                sugar = C*z+D*w
                if sugar <= sugarMAX:
                    if ans[1]*(sugar+water) < sugar*ans[0]:
                        ans = [sugar+water, sugar]
                else:
                    break
print(*ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

ws = set()
for i in range(31):
    for j in range(31):
        v = a*i + b*j
        if 0 < v <= f:
            ws.add(v) 
waters = list(ws)
waters.sort()

ss = set()
for i in range(3001):
    for j in range(3001):
        v = i*c +j*d
        if v <= f:
            ss.add(v)
        else:
            break 

sugars = list(ss)
sugars.sort()

max_sugar, max_water = 0, waters[0]
for w in waters:
    s_max1 = f - w
    s_max2 = (w//100)*e
    s_max = min(s_max1, s_max2)
    ind = bisect_right(sugars, s_max) - 1
    ind = ind if 0 <= ind < len(sugars) else None
    if ind is None:
        continue
    else:
        sugar = sugars[ind] if ind is not None else None
        if sugar*(max_sugar+max_water) > max_sugar*(sugar+w):
            max_sugar = sugar
            max_water = w

print(max_sugar+max_water, max_sugar)

Submission status: Accepted

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

ws = set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1,100*B):
        if a+b > F: break
        ws.add(a+b)
ws.remove(0)

ss = set()
for c in range(0,F+1,C):
    for d in range(0,F+1,D):
        if c+d > F: break
        ss.add(c+d)

best_s = -1
best_w = 1
for w in ws:
    for s in ss:
        if w+s > F: continue
        if E*w < s*100: continue
        if best_s * (s+w) < s * (best_s + best_w):
            best_s = s
            best_w = w
print(best_s+best_w, best_s)

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    A, B, C, D, E, F = LI()

    # 水と砂糖の用意できるパターンを列挙
    w = set()
    for i in range(F // (100 * A) + 1):
        for j in range((F - i * 100 * A) // (100 * B) + 1):
            if i != 0 and i != 0:
                w.add(i * A + j * B)
    # print(w)

    s = set()
    for i in range(F // C + 1):
        for j in range((F - i * C) // D + 1):
            s.add(i * C + j * D)
    # print(s)

    # 全探索で間にあう(2分探索不要)
    # 初期値として水100Aの0%砂糖水を設定
    ans = [A, 0]
    for i, j in itertools.product(w, s):
        if 100 * i + j <= F and j <= i * E:
            # 100j/(100i+j) > 100ans[1]/(100ans[0]+ans[1])
            if j * (100 * ans[0] + ans[1]) > ans[1] * (100 * i + j):
                ans[0] = i
                ans[1] = j

    print(ans[0] * 100 + ans[1], ans[1])

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    A, B, C, D, E, F = LI()

    # 水と砂糖の用意できるパターンを列挙
    # 水に対して砂糖の量を2分探索
    w = set()
    for i in range(F // (100 * A) + 1):
        for j in range((F - i * 100 * A) // (100 * B) + 1):
            if i != 0 and i != 0:
                w.add(i * A + j * B)
    # print(w)

    s = set()
    for i in range(F // C + 1):
        for j in range((F - i * C) // D + 1):
            s.add(i * C + j * D)
    s = list(s)
    s.sort()
    # print(s)

    ans = [A, 0]
    c = 0
    for i in w:
        ng = len(s)
        ok = -1
        while abs(ok-ng)>1:
            m = (ng+ok)//2
            if s[m] <= E * i and s[m] + 100 * i <= F:
                ok = m
            else:
                ng = m
        if 0 <= ok < len(s) and 100 * s[ok] / (i + s[ok]) > c:
            ans = [i, s[ok]]
            c = 100 * s[ok] / (i + s[ok])

    print(ans[0] * 100 + ans[1], ans[1])

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
A,B,C,D,E,F = (int(T) for T in input().split())
SugM = 0
WatM = 100*A
for TC in range(0,F+1):
    for TD in range(0,F+1):
        Suger = C*TC+D*TD
        RestS = F-Suger
        if RestS>=0:
            for TA in range(0,(RestS//100)+1):
                for TB in range(0,(RestS//100)+1):
                    if TA==TB==0:
                        continue
                    else:
                        Water = TA*A*100+TB*B*100
                        RestW = RestS-Water
                        if RestW>=0 and Water>=(100*Suger)/E:
                            if SugM/(WatM+SugM)<Suger/(Water+Suger):
                                SugM = Suger
                                WatM = Water
                        else:
                            break
        else:
            break
print('{} {}'.format(WatM+SugM,SugM))

Submission status: Accepted

Solution code:
A,B,C,D,E,F = (int(T) for T in input().split())
SugM = 0
WatM = 100*A
for TA in range(0,(F//100)+1):
    for TB in range(0,(F//100)+1):
        if TA==TB==0:
            continue
        else:
            Water = TA*100*A+TB*100*B
            RestW = F-Water
            if RestW>=0:
                for TC in range(0,RestW+1):
                    for TD in range(0,RestW+1):
                        Suger = TC*C+TD*D
                        RestS = RestW-Suger
                        if RestS>=0 and Water>=(100*Suger)/E:
                            if Suger/(Suger+Water)>SugM/(SugM+WatM):
                                SugM = Suger
                                WatM = Water
                        else:
                            break
            else:
                break
print('{} {}'.format(WatM+SugM,SugM))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans1 = A
ans2 = 0
for i in range(A, F // 100 + 1):
  if any((i - A * j) % B == 0 for j in range(i // A + 1)):
    x = min(E * i, F - i * 100)
    e = max([C * j + (x - C * j) // D * D for j in range(x // C + 1)])
    if e * ans1 > ans2 * i:
      ans1 = i
      ans2 = e
print(ans1 * 100 + ans2, ans2)

Submission status: Accepted

Solution code:
def main():
    a, b, c, d, e, f = map(int, input().split())
    max_weight = f // 100
    best_water = a
    best_suger = 0
    best_density = 0
    is_ideal = False
    for water in range(a, max_weight + 1):
        max_a = water // a
        max_b = water // b
        is_exist = False

        for add_a in range(max_a):
            water_a = (add_a + 1) * a
            is_exist = water_a + (water - water_a) // b * b == water
            if is_exist:
                break

        if not is_exist:
            for add_b in range(max_b):
                water_b = (add_b + 1) * b
                is_exist = water_b + (water - water_b) // a * a == water
                if is_exist:
                    break

        if is_exist:
            max_suger = e * water
            remaining = min(f - water * 100, max_suger)
            max_c = remaining // c
            max_d = remaining // d

            for add_c in range(max_c):
                sugar_c = (add_c + 1) * c
                sugar = sugar_c + (remaining - sugar_c) // d * d
                density = sugar / (water + sugar)
                if density > best_density:
                    best_density = density
                    best_water = water
                    best_suger = sugar
                    is_ideal = sugar == max_suger
                    if is_ideal:
                        break

            if not is_ideal:
                for add_d in range(max_d):
                    sugar_d = (add_d + 1) * d
                    sugar = sugar_d + (remaining - sugar_d) // c * c
                    density = sugar / (water + sugar)
                    if density > best_density:
                        best_density = density
                        best_water = water
                        best_suger = sugar
                        is_ideal = sugar == max_suger
                        if is_ideal:
                            break
            if is_ideal:
                break

    print(f'{best_water * 100 + best_suger} {best_suger}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
dens = 0
ans_water = 100*min(A, B)
ans_sugar = 0
for i in range(31):
    for j in range((F-(100*A*i))//(100*B)+1):
        for k in range((F-(100*A*i)-(100*B*j))//C+1):
            for l in range((F-(100*A*i)-(100*B*j)-(C*k))//D+1):
                water = 100*A*i+100*B*j
                sugar = C*k+D*l
                if water == 0:
                    break
                if sugar <= E*(A*i+B*j):
                    if dens<sugar/(sugar+water):
                        dens = sugar/(sugar+water)
                        ans_water = water
                        ans_sugar = sugar
print(ans_water+ans_sugar, ans_sugar)

Submission status: Accepted

Solution code:
#
# abc074 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """1 2 10 20 15 200"""
        output = """110 10"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 2 1 2 100 1000"""
        output = """200 100"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """17 19 22 26 55 2802"""
        output = """2634 934"""
        self.assertIO(input, output)


def resolve():
    A, B, C, D, E, F = map(int, input().split())
    N = 0
    W = 100*A
    S = 0
    for i in range(31):
        for j in range(31):
            for k in range(101):
                for l in range(101):
                    w = A*i+B*j
                    s = C*k+D*l
                    if w == 0 or 100*w+s > F or s > w*E:
                        break
                    n = 100*s / (100*w+s)
                    if n > N:
                        N = n
                        W = 100*w+s
                        S = s
    print(f"{W} {S}")


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
def main():
	A, B, C, D, E, F = map(int, input().split())
	water = set()
	sugar = set()

	for i in range(F // (100 * A) + 1):
		for j in range(F // (100 * B) + 1):
			water_amount = 100 * A * i + 100 * B * j
			if 0 < water_amount and water_amount <= F:
				water.add(water_amount)

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

	# print(water)
	# print(sugar)

	max_c = -1
	max_w = 0
	max_s = 0

	for w in water:
		for s in sugar:
			if w + s <= F:
				if s / w <= E / 100:
					if s * 100 / (w + s) > max_c:
						max_c = s * 100 / (w + s)
						max_w = w
						max_s = s

	print(max_w + max_s, max_s)

 
if __name__ == "__main__":
  	main()

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

#まず容器fグラムに入る分の砂糖の組み合わせを考える。
suger = []
for i in range(0, f+1):
    for j in range(0, f+1):
        tmp = c*i + d*j
        if (tmp <= f):
            suger.append(tmp)
suger = list(set(suger))

#次に容器fグラムに入る分の水の組み合わせを考える
watter = []
for i in range(0, f+1, 100):
    for j in range(0, f+1, 100):
        tmp = (a*i + b*j)
        if (tmp <= f):
            watter.append(tmp)

watter = list(set(watter))

#sugerとwatterの組み合わせを列挙して、条件を満たすもので濃度を列挙する
max_conset = -1.0
ans_watter = 0
ans_sugger = 0

#print(watter)
#print(suger)

for i in range(len(watter)):
    for j in range(len(suger)):

        if (0 < suger[j] + watter[i] <= f):
            if (watter[i] // 100 * e >= suger[j]):
                consent = 100 * suger[j] / (watter[i] + suger[j])
                if (max_conset < consent):
                    ans_watter = watter[i] + suger[j]
                    ans_sugger = suger[j]
                    max_conset = consent

print(ans_watter, ans_sugger)

Submission status: Accepted

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

x = []
for i in range(0,F+1,A*100):
    for j in range(0,F+1,B*100):
        water = i + j
        if water > F:
            break
        x.append(water)

y = []
for i in range(0,F+1,C):
    for j in range(0,F+1,D):
        sugar = i + j
        if sugar > F:
            break
        y.append(sugar)

x = sorted(set(x))[1::]
y = sorted(set(y))

n = 0
WS = S = 0
for w in x:
    for s in y:
        if w + s > F:
            break
        if w * E//100 >= s:
            m = 100 * s / (w + s)
            if m >= n:
                n = m
                WS, S = w + s , s

print(WS,S)

Submission status: Accepted

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

x = sorted(set([w for i in range(0,F+1,A*100) for j in range(0,F+1,B*100) if (w := i + j) < F]))[1::]
y = sorted(set([s for i in range(0,F+1,C) for j in range(0,F+1,D) if (s := i + j) < F]))

n = 0
WS = S = 0
for w in x:
    for s in y:
        if w + s > F:
            break
        if w * E//100 >= s:
            m = s / (w + s)
            if m >= n:
                n = m
                WS, S = w + s , s

print(WS,S)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    a, b, c, d, e, f = ns()
    max_cncnt, ans_sum, ans_sugar = -1, 0, 0

    sugar_cand = []
    sugar_dp = [False for _ in range(f + 1)]
    sugar_dp[0] = True
    for i in range(f + 1):
        if sugar_dp[i]:
            if i + c <= f:
                sugar_dp[i + c] = True
            if i + d <= f:
                sugar_dp[i + d] = True
            sugar_cand.append(i)

    for i in range(f // (100 * a) + 1):
        for j in range(f // (100 * b) + 1):
            water = 100 * (a * i + b * j)
            if water == 0:
                continue
            if water > f:
                break
            sugar_lim = min(water * e // 100, f - water)
            sugar_idx = bisect.bisect_right(sugar_cand, sugar_lim)
            sugar = 0 if sugar_idx == 0 else sugar_cand[sugar_idx - 1]
            if max_cncnt < sugar / (water + sugar):
                ans_sum = water + sugar
                ans_sugar = sugar
                max_cncnt = ans_sugar / ans_sum

    print(ans_sum, ans_sugar)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
waters = []
for i in range(31):
    for j in range(31):
        v = 100*a*i + 100*b*j
        if v <= f and v != 0:
            waters.append(v)

waters = list(set(waters))
ans_vol, ans_sug = waters[0], 0
for w in waters:
    rem = f - w
    max_s = e*w//100
    max_s = min(rem, max_s)
    for c_cnt in range(max_s//c+1):
        cs = c_cnt*c
        rem_d = max_s - cs
        d_cnt = rem_d//d
        ds = d_cnt*d
        sug = cs+ds
        vol = sug + w
        if ans_sug*vol < sug*ans_vol:
            ans_vol, ans_sug = vol, sug

print(ans_vol, ans_sug)

Submission status: Accepted

Solution code:
import bisect
A, B, C, D, E, F = map(int, input().split())
water = []
sugar = []

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

water = list(set(water))

for i in range(F//C+1):
  for j in range(F//D+1):
    if C*i + D*j <= F:
      sugar += [C*i + D*j]

sugar = list(set(sugar))
sugar = sorted(sugar)
ans_sw = 0
ans_s = 0
ans = 0
for w in water:
  s = min((E/100)*w, F-w)
  idx = bisect.bisect_right(sugar, s)
  if w + sugar[idx-1] == 0:
    continue
  conc = (sugar[idx-1]/(w+sugar[idx-1]))*100
  if ans < conc:
    if sugar[idx-1] <= (E/100)*w and sugar[idx-1] + w <= F:
      ans = conc
      ans_sw = w + sugar[idx-1]
      ans_s = sugar[idx-1]
if ans_sw == 0:
  ans_sw = 100*A
print(ans_sw, ans_s)

Submission status: Accepted

Solution code:
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] - is True if i gram of sugar is obtainable
    A, B, C, D, E, F = read_ints()
    dp = [0]*(F+1)
    for i in range(1, F+1):
        dp[i] = dp[i-1]
        if i-C >= 0:
            dp[i] = max(dp[i], dp[i-C]+C)
        if i-D >= 0:
            dp[i] = max(dp[i], dp[i-D]+D)

    highest_ratio = [0, 100*A]

    for a in range(31):
        for b in range(31):
            water = 100*A*a+100*B*b
            if water < F:
                sugar_limit = min(E*water//100, F-water)
                sugar = dp[sugar_limit]
                if sugar*highest_ratio[1] > water*highest_ratio[0]:
                    highest_ratio = [sugar, water]
    return sum(highest_ratio), highest_ratio[0]


if __name__ == '__main__':
    print(*solve())

Submission status: Accepted

Solution code:
import math


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] - is True if i gram of sugar is obtainable
    A, B, C, D, E, F = read_ints()
    dp = [False]*(F+1)
    dp[0] = True
    for i in range(F+1):
        if i+C < F+1:
            dp[i+C] = dp[i+C] or dp[i]
        if i+D < F+1:
            dp[i+D] = dp[i+D] or dp[i]
    # dp2[i] - highest gram of sugars that is not greater than i
    dp2 = [0]*(F+1)
    highest_sugar = 0
    for i in range(F+1):
        if dp[i]:
            dp2[i] = highest_sugar = i
        else:
            dp2[i] = highest_sugar

    highest_ratio = [0, 100*A]

    for a in range(31):
        for b in range(31):
            water = 100*A*a+100*B*b
            if water < F:
                sugar_limit = min(E*water//100, F-water)
                sugar = dp2[sugar_limit]
                if sugar*highest_ratio[1] > water*highest_ratio[0]:
                    highest_ratio = [sugar, water]
    return sum(highest_ratio), highest_ratio[0]


if __name__ == '__main__':
    print(*solve())

Submission status: Accepted

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

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

A = A*100
B = B*100

Alim =F//A
Blim = F//B
water = []
for ai in range(Alim+1):
    for bi in range(Blim+1):
        tmp = ai*A+bi*B
        if tmp <=F:
            water.append(tmp)
water = set(water)

suger_limit = math.ceil(F/100)*E
Clim = suger_limit//C
Dlim = suger_limit//D
suger = []
for ci in range(Clim+1):
    for di in range(Dlim+1):
        tmp = ci*C+di*D
        if tmp <=suger_limit:
            suger.append(tmp)
suger = sorted(list(set(suger)),reverse=1)

#judge = 0
candi = [[0,0]]
#limCon=100*E/(100+E)

while water:
    w = water.pop()
    for su in suger:
        
        if w+su > F:
            continue
        else:
            if w*E>=su*100:
                candi.append([w+su,su])
                break
ans = [0,0]
judge = 0
for can in candi:
    ws,s = can
    if ws == 0:
        continue
    else:
        con = s/ws*100
        if con >= judge:
            ans = [ws,s]
            judge=con
  
print(*ans)

Submission status: Accepted

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

limit_water = f * 100 / (100 + e)
limit_suger = f * e / (100 + e)


waters = []
sugars = []

for i in range(31):
    for j in range(31):
        water = 100 * a * i + 100 * b * j
        if water != 0 and water <= 3000:
            waters.append(water)

for i in range(1500):
    for j in range(1500):
        sugar = c * i + d * j
        sugars.append(sugar)

ans = []
max_density = 0.0

sugars = list(set(sugars))
sugars.sort()
waters = list(set(waters))
waters.sort()

for water in waters:
    for sugar in sugars:
        if sugar + water <= f and sugar <= (water * e / 100):
            density = sugar / (sugar + water)
            if density >= max_density:
                ans = [water + sugar, sugar]
                max_density = density

print(*ans)

Submission status: Accepted

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

concentration = 0
ans = [A*100,0]

water = []
for a in range(F//(A*100) + 1):
  for b in range(((F-a*A*100)//(B*100))+1):
    water.append((a*A+b*B)*100)
    
water = sorted(list(set(water)))

sugar = []
for c in range(F//C + 1):
  for d in range(((F - c*C)//D)+1):
    sugar.append(c*C+d*D)
sugar = sorted(list(set(sugar)))


for wa in water:
  for su in sugar:
    if wa + su <= F:
      if su <= (wa/100)*E:
        if wa != 0:
          if concentration < su/(su+wa):
            concentration = su/(su+wa)
            ans = [su+wa,su]

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