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

# 作りうる水の量を洗い出す
waters = set()

for i in range(F//(100*A) + 1):
    for j in range((F-100*A*i)//(100*B) + 1):
        w = 100*A*i + 100*B*j
        if w != 0:
            waters.add(w)
waters = list(waters)
waters.sort()


sugars = set()
# Cを何回入れるか
for i in range(F//C + 1):
    # Dを何回いれるか
    for j in range((F - C*i) // D + 1):
        s = i*C + j*D
  
        sugars.add(s)


sugars = list(sugars)
sugars.sort()

# 最大濃度
max_conc = -1
# 最大濃度の時の水と砂糖
water = -1
sugar = -1




for w in waters:
    for s in sugars:

        # 容量を超えたらアウト
        if w+s > F: break
        # 解けきれない量でもアウト
        if s*100 > w * E: break

        conc = s / (s+w)
        if conc > max_conc:
            max_conc = conc
            water = w
            sugar = s

print(sugar+water, sugar)

Submission status: Accepted

Solution code:



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

# 作りうる水の量を洗い出す
waters = set()

for i in range(F//(100*A) + 1):
    for j in range((F-100*A*i)//(100*B) + 1):
        w = 100*A*i + 100*B*j
        if w != 0:
            waters.add(w)
waters = list(waters)
waters.sort()


sugars = set()
# Cを何回入れるか
for i in range(F//C + 1):
    # Dを何回いれるか
    for j in range((F - C*i) // D + 1):
        s = i*C + j*D
  
        sugars.add(s)


sugars = list(sugars)
sugars.sort()

# 最大濃度
max_conc = 0
# 最大濃度の時の水と砂糖
total = 0
sugar = 0

best_w = best_s = best_r = -1
for water in sorted(waters):
    for sugar in sorted(sugars):
        if water + sugar > F: break
        if water*E < sugar*100: break
        rate = sugar / (water + sugar)
        if rate > best_r:
            best_r = rate
            best_w = water
            best_s = sugar
print(best_s+best_w, best_s)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100
# 溶ける最大濃度
limit = E / (100+E)

# dp[i][j] := 水i、砂糖jの状態を実現可能か
dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        # 枝刈り
        if i+j > F:
            break
        # 実現可能な状態なら、4つの行動を遷移させる
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = 0
mx = -1
for a in range(F+1):
    for b in range(F+1):
        if a == b == 0:
            continue
        if a+b > F:
            break
        if dp[a][b]:
            x = b / (a+b)
            # 濃度が濃すぎて溶け切らない
            if x > limit:
                continue
            # 最大濃度の更新
            if mx < x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100
# 溶ける最大濃度
limit = E / (100+E)

# dp[i][j] := 水i、砂糖jの状態を実施可能か
dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        # 枝刈り
        if i+j > F:
            break
        # 実施可能な状態なら、4つの行動を遷移させる
        if i+A <= F:
            dp[i+A][j] |= dp[i][j]
        if i+B <= F:
            dp[i+B][j] |= dp[i][j]
        if j+C <= F:
            dp[i][j+C] |= dp[i][j]
        if j+D <= F:
            dp[i][j+D] |= dp[i][j]

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            # 濃度が濃すぎて溶け切らない
            if x > limit:
                continue
            # 最大濃度の更新
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100
# 溶ける最大濃度
limit = E / (100+E)

# dp[i][j] := 水i、砂糖jの状態を実施可能か
dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        # 枝刈り
        if i+j > F:
            break
        # 実施可能な状態なら、4つの行動を遷移させる
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            # 濃度が濃すぎて溶け切らない
            if x > limit:
                continue
            # 最大濃度の更新
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F =  MAP()
A *= 100
B *= 100
# 溶ける最大濃度
limit = E / (100+E)

# dp[i][j] := 水i、砂糖jの状態を実施可能か
dp = list2d(F+1, F+1, 0)
dp[0][0] = 1
for i in range(F+1):
    for j in range(F+1):
        # 枝刈り
        if i+j > F:
            continue
        # 実施可能な状態なら、4つの行動を遷移させる
        if dp[i][j]:
            if i+A <= F:
                dp[i+A][j] = 1
            if i+B <= F:
                dp[i+B][j] = 1
            if j+C <= F:
                dp[i][j+C] = 1
            if j+D <= F:
                dp[i][j+D] = 1

ans1 = ans2 = mx = 0
for a in range(F+1):
    for b in range(F+1):
        if a+b > F:
            break
        if a == b == 0:
            continue
        if dp[a][b]:
            x = b / (a+b)
            # 濃度が濃すぎて溶け切らない
            if x > limit:
                continue
            # 最大濃度の更新
            if mx <= x:
                mx = x
                ans1 = a + b
                ans2 = b
print(ans1, ans2)

Submission status: Accepted

Solution code:
import sys

A, B, C, D, E, F = map(int, sys.stdin.readline().split())
E = 100 * E / (100 + E)

def main():
    w = set()
    for w1 in range(0, F+1, 100*A):
        for w2 in range(0, F-w1+1, 100*B):
            w.add(w1 + w2)

    s = set()
    for s1 in range(0, F+1, C):
        for s2 in range(0, F-s1+1, D):
            s.add(s1 + s2)
            
    w = sorted(w)
    s = sorted(s)

    res = set()
    for i in w[1:]:
        for j in s:
            if i + j > F:
                break
            sol = 100 * j / (i + j)
            if sol <= E:
                res.add((sol, i+j, j))

    res = sorted(res, reverse=True)
    return res[0][1], res[0][2]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Submission status: Accepted

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

max_concentration = 0
res = (0, 0)
for i in range(0, f//(100*a)+1):
    for j in range(0, (f-100*a*i)//(100*b)+1):
        water = 100 * (a*i + b*j)
        if water == 0:
            continue
        for k in range(0, f-i-j+1):
            for l in range(0, f-i-j-k+1):
                sugar = c*k + d*l
                if water + sugar > f:
                    break
                if sugar > water//100 * e:
                    break
                if water + sugar == 0:
                    continue
                concentration = sugar / (water+sugar)
                if concentration >= max_concentration:
                    max_concentration = concentration
                    res = (water+sugar, sugar)

print(*res)

Submission status: Accepted

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

tmp = np.arange(f+1, dtype=int)
water = np.zeros(f+1, dtype=int)
water[0] = 1
for i in range(f):
    if water[i]:
        if i+100*a < f+1:
            water[i + 100 * a] = 1
        if i+100*b < f+1:
            water[i + 100 * b] = 1
water = tmp[water == 1]
capacity = water//100*e
capacity = np.minimum(capacity, f-water)

sugar = np.zeros(f + 1, dtype=int)
sugar[0] = 1
for i in range(f):
    if sugar[i]:
        if i+c < f+1:
            sugar[i + c] = 1
        if i+d < f+1:
            sugar[i + d] = 1
sugar = tmp[sugar == 1]

max_d = 0
pair = 100 * a, 0
s = np.searchsorted(sugar, capacity, side="right")
s = sugar[s-1]
s = s[1:]
water = water[1:]
i = np.argmax(s / (water + s))
print(water[i]+s[i], s[i])

Submission status: Accepted

Solution code:
abcdef = list(map(int, input().split()))
a, b, c, d, e, f = abcdef[0] * 100, abcdef[1] * 100, abcdef[2], abcdef[3], abcdef[4], abcdef[5]

fa = int(f / a)
fb = int(f / b)
maxc = int(int(f / 100) * e / c)
maxd = int(int(f / 100) * e / d)

res = -1
suger_max = -1
nowden = -1

# 砂糖は水100グラムにEグラム解ける.(max 100)
# a,b,c,dを(i,j,k,l)回入れるとする.i*j < 10^3で k*j < 3000 * 1500くらい…行けるか？
# もう少し工夫要りそう

for i in range(fa + 1):
    for j in range(fb + 1):
        for k in range(maxc + 1):
            for l in range(maxd + 1):
                if i == 0 and j == 0:
                    continue
                wat = a * i + b * j
                sug = c * k + d * l
                if wat + sug > f or sug / wat > e / 100:
                    continue
                else:
                    den = sug / (wat + sug)
                    if (nowden < den):
                        nowden = den
                        res = wat + sug
                        suger_max = sug

print(str(res) + " " + str(suger_max))

Submission status: Accepted

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

water=[]
for i in range(31):
    for j in range(30):
        if (A*i+B*j)*100<=F:
            water.append((A*i+B*j)*100)
sugar=[]
for i in range(501):
    for j in range(500):
        if C*i+D*j<=F//2:
            sugar.append(C*i+D*j)

ans_sum=A*100
ans_sugar=0
ans_rate=0
for i in water:
    for j in sugar:
        if i==0:
            continue
        if i+j<=F and ans_rate<j/i<=E/100:
            ans_sum=i+j
            ans_sugar=j
            ans_rate=j/i

print(ans_sum,ans_sugar)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
# a = 100 * a(g)の水を入れる
# b = 100 * b(g)の水を入れる
# c = c(g)の砂糖を入れる
# d = d(g)の砂糖を入れる
# e = 100(g)あたりの水に溶ける砂糖
# f = 水の質量と砂糖の質量の合計
# 砂糖水の濃度 = 100 * b / (a + b) (%)
# 答え = 1つ目は求める砂糖水の質量、2つ目はそれに溶けている砂糖の質量

xs = set()
ys = set()

a_limit = f // (100 * a)
for i in range(a_limit + 1):
    b_limit = (f - (100 * a * i)) // (100 * b)
    for j in range(b_limit + 1):
        if i == 0 and j == 0:
            continue
        x = 100 * a * i + 100 * b * j
        xs.add(x)

c_limit = f // c
for i in range(c_limit + 1):
    d_limit = (f - c * i) // d
    for j in range(d_limit + 1):
        y = c * i + d * j
        ys.add(y)

density_limit = e / (100 + e)
max_density = 0.0
w = 0
s = 0
for x in xs:
    for y in ys:
        density = y / (x + y)
        if f >= x + y and density_limit >= density and density >= max_density:
            max_density = density
            w = x + y
            s = y

print(w, s)

Submission status: Accepted

Solution code:
from bisect import bisect_left
a, b, c, d, e, f = map(int, input().split())
mw = []
for i in range(31):
    for j in range(31):
        mw.append(a * i + b * j)
mw.sort()

ms = []
for i in range(3001):
    for j in range(3001):
        ms.append(- (c * i + d * j))

ms.sort()

ans = 0
ans_mw = mw[1]
ans_ms = 0

for mwi in mw[1:]:
    if mwi * 100 > f:
        break
    target = min(f - mwi * 100, mwi * e)
    msi = -ms[bisect_left(ms, - target)]
    cand = msi / mwi
    if mwi * 100 + msi <= f and cand > ans:
        ans = cand
        ans_mw = mwi
        ans_ms = msi

print(ans_mw * 100 + ans_ms, ans_ms)

Submission status: Accepted

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

Water = []
Sugar = []

for i in range(0,31):
    for j in range(0,16):
        w = 100*a*i + 100* b*j
        if w <= f:
            Water.append(w)

Water = set(Water)
Water.remove(0)

for k in range(0,3001):
    for l in range(0,1501):
        s = c*k + d*l
        if s <= f:
            Sugar.append(s)

Sugar = set(Sugar)

ans_conc = 0
ans_water = 0
ans_sugar = 0
max_conc = (100*e)/(100+e)

for w in Water:
    for s in Sugar:
        conc = (100 * s) /(w + s)
        if (conc <= max_conc) and (w+s <= f) and (ans_conc <= conc):
            ans_conc = conc
            ans_water = w
            ans_sugar = s 
            
print(str(ans_water+ans_sugar) + ' ' + str(ans_sugar))

Submission status: Accepted

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

water = []
for i in range(F//(A*100) + 1):
    for j in range(F//(B*100) + 1):
        n = (i*A + j*B)*100
        if n <= F:
            water.append(n)
water = sorted(list(set(water)))

density_d = {}
density = []

for i in water:
    suger_limit = E*(i//100)

    suger = []

    for j in range(suger_limit//C + 1):
        for k in range(suger_limit//D + 1):
            n = j*C + k*D
            if n <= suger_limit and n + i <= F:
                suger.append(n)
    suger = max(suger)
    if i+suger == 0:
        continue
    else:
        density.append(100*suger/(i+suger))
        density_d[100*suger/(i+suger)] = [i + suger, suger]
density = list(set(density))
a, b = map(int, density_d[max(density)])
print(a,b)

Submission status: Accepted

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

water = []
for i in range(31):
    for j in range(31):
        tmp = 100*i*A + 100*j*B
        if tmp <= F:
            water.append(tmp)
            
water = list(set(water))
water.remove(0)

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

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

#水を100ずつ区切って考える
A, B, C, D, E, F = rl()
water = [False for x in range(F//100 + 1)]
answer = (-1, 0, 0)
for i in range(F//(100*B) + 1):
    for j in range(F//(100*A) + 1):
        k = i * B + j * A
        if k > len(water) - 1:
            continue
        water[k] = True
for i in range(len(water)):
    if water[i] == True:
        water[i] = i
for x in water:
    if not x or x == 0:
        continue
    max = x * E
    for i in range(max//D+1):
        for j in range(max//C+1):
            y = D * i + C * j
            solution = x*100 + y
            if solution > F:
                break
            if y > max:
                break
            elif solution > 0:
                result = y / solution
                if result > answer[0]:
                    answer = (result, solution, y)

print(answer[1], answer[2])

Submission status: Accepted

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

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

suger = [0] * (F + 1)
suger[0] = 1
for i in range(F + 1):
  if suger[i]:
    if i + C < F + 1: suger[i+C] = 1
    if i + D < F + 1: suger[i+D] = 1
#print(suger)

max_sol = -1
answer = [0, 0]
for i in range(len(water)):
  if water[i] == 0:
    continue
  #print(i)
  for j in range(len(suger)):
    if suger[j] and i*100 + j <= F and j / (i*100 + j) <= E / (100 + E):
        if max_sol < 100 * j / (i*100 + j):
          max_sol = 100 * j / (i*100 + j)
          answer = [i*100 + j, j]
print(*answer)

Submission status: Accepted

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

#print(answer)
print(str(ans[0]) + " " + str(ans[1]))

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
import math
import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase

#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True

A,B,C,D,E,F=LI()

m=0
ans=(A*100,0)
for a in range(31):
    for b in range(16):
        for c in range(101):
            for d in range(101):
                if a*A*100+b*B*100+c*C+d*D<=F and (a*A+b*B)*E>=c*C+d*D and a+b>0:
                    if m<(c*C+d*D)/(a*A+b*B):
                        m=(c*C+d*D)/(a*A+b*B)
                        ans=(100*(a*A+b*B)+c*C+d*D,c*C+d*D)

print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
d=0
ans=(100*A,0)
for x in range(F//(100*A)+1):
    for y in range((F-x*100*A)//(100*B)+1):
        if x+y==0:
            continue
        for z in range((F-x*100*A-y*100*B)//C+1):
            for w in range((F-x*100*A-y*100*B-z*C)//D+1):                
                if (x*A+y*B)*E>=(z*C+w*D) and d<100*(z*C+w*D)/(100*(x*A+y*B)+(z*C+w*D)):                    
                    d=100*(z*C+w*D)/(100*(x*A+y*B)+(z*C+w*D))
                    # print((x,y,z,w))                
                    # print((100*(x*A+y*B)+(z*C+w*D),(z*C+w*D),d))
                    ans=(100*(x*A+y*B)+(z*C+w*D),(z*C+w*D))

print(*ans)

Submission status: Accepted

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

def func(ans1,sugar):
    if sugar == 0:
        return 0
    else:
        ans = sugar * 100 / ans1
        return ans

sugar = 0
ans1 = 100 * a
max_a = f // (a * 100)

#操作１
for i in range(1, max_a + 1):
    max_b = (f - 100 * i * a) // (100 * b)
    #操作２
    for j in range(max_b +1):
        water = 100 * a * i + 100 * b * j
        #可能な砂糖の量
        max_sugar = (a * i + b * j) * e
        #最大濃度に近い
        if water + max_sugar <= f:
            max_c = max_sugar // c
            for k in range(max_c + 1):
                max_d = (max_sugar - k * c) // d
                if func(ans1, sugar) < func(water + (k * c + max_d * d) , (k * c + max_d * d)):
                    sugar = (k * c + max_d * d)
                    ans1 = water + sugar
        #濃度を薄める
        else:
            max_sugar = f - water
            min_sugar = c
            if min_sugar <= e:
                for k in range(e // min_sugar + 1):
                    max_d = (max_sugar - k * c) // d
                    if func(ans1, sugar) < func(water + (k * c + max_d * d), (k * c + max_d * d)):
                        sugar = (k * c + max_d * d)
                        ans1 = water + sugar

print(ans1,sugar)

Submission status: Accepted

Solution code:
from bisect import bisect_right
a, b, c, d, e, f = map(int, input().split())
suger = [0] * ((f // c + 1) * (f // d + 1))
idx = 0
for i in range(f // c + 1):
    for j in range(f // d + 1):
        suger[idx] = c * i + d * j
        idx += 1
suger.sort()
ans1, ans2 = 0, 0
ma = -1
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        w = a * i + b * j
        if f < 100 * w:
            continue
        s = suger[bisect_right(suger, min(w * e, f - 100 * w)) - 1]
        if w != 0 and ma < s / (100 * w + s):
            ma = s / (100 * w + s)
            ans1 = w
            ans2 = s
print(ans1 * 100 + ans2, ans2)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    a, b, c, d, e, f = LI()
    lis = []
    for i in range(f //c + 1):
        for k in range(f // d + 1):
            lis.append(c * i + d * k)
    lis = list(set(lis))
    lis.sort()
    ans = [100 * a, 0]
    for i in range(f // 100 + 1):
        for k in range(f // 100 + 1):
            if i == k == 0:
                continue
            water = a * i + b * k
            if water * 100 > f:
                continue
            E = min(f - water * 100, water * e)
            if E <= 0:
                continue
            aa = bisect_right(lis, E) - 1
            if aa == -1:
                continue
            aa = lis[aa]
            if ans[1] / ans[0] < aa / (water * 100 + aa):
                ans = [water * 100 + aa, aa]
    print(*ans)

    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

mxdensity=e/(100+e)
mxinput=f
templ=[]

#初期値設定
newdensity=0
newl=[100*a,0]
for i in range(31):
  for j in range(31):
    for k in range(101):
      for l in range(101):
        water=100*a*i+100*b*j
        sugar=c*k+d*l
        total=water+sugar
        if water==0 or (water+sugar)==0:
          break
        if total>mxinput:
          break
        if (sugar/total)<=mxdensity:
          #templ.append([water,sugar])
          tempdensity=sugar/total
          if tempdensity>newdensity:
            newdensity=tempdensity
            newl=[water,sugar]

print("{0} {1}".format(sum(newl),newl[1]))

Submission status: Accepted

Solution code:
# ABC074 C - Sugar Water
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b,c,d,e,f = nm()
L =[]
for aa in range(0,31):
    for bb in range(0,31):
        for cc in range(0,101):
            for dd in range(0,101):
                if 100*a<=100*a*aa+100*b*bb+c*cc+d*dd<=f:
                    L.append((aa,bb,cc,dd))

max_w = 0.0
idx = 10*7
for i,l in enumerate(L):
    # water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
    sugar = c*l[2]+d*l[3]
    if (100+e)*100*sugar<=(100*e)*water:
        # if water!=0 and (l[0]>0 or l[1]>0):
        if l[0]>0 or l[1]>0:
            t = (sugar/water)*100
            if t>=max_w:
                max_w=t
                idx = i

for i,l in enumerate(L):
    if i==idx:
        water = 100*a*l[0]+100*b*l[1]+c*l[2]+d*l[3]
        sugar = c*l[2]+d*l[3]
        print(water,sugar)
        exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, C, D, E, F):
    ans = 0
    w = set()
    for i in range(F//A + 1):
        for j in range(F//B + 1):
            m = 100*(i*A + j*B)
            if m < F:
                w.add(m)
    mw = max(w)


    ms = (mw // 100) * E
    s = set()
    for i in range(ms+1):
        for j in range(ms+1):
            s.add(i*C + j*D)
    W = sorted(w)
    S = sorted(s)

    ans = (0, A*100, 0)
    for w in W:
        if w == 0:
            continue
        ts = w // 100 * E
        if F < ts + w:
            ts = F - w
        si = bisect.bisect_left(S, ts)
        if S[si] == ts:
            s = ts
        else:
            if si == 0:
                continue
            s = S[si-1]
        if s + w <= F and  s / w > ans[0]:
            ans = (s/w, w + s, s)
    return ' '.join(map(str, ans[1:]))


def main():
    A, B, C, D, E, F = read_int_n()
    print(slv(A, B, C, D, E, F))


if __name__ == '__main__':
    main()