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:
from collections import deque
a,b,c,d,e,f = map(int,input().split())

def judgement(x,y):
    flag = True
    if 100*y > e*x:
        flag = False
    if x+y > f:
        flag = False
    return flag


q = deque([(100*a, 0)])
used = set()
used.add((100*a, 0))
if 100*b <= f:
    q.append((100*b, 0))
    used.add((100*b, 0))
ans = (100*a,0)
per = 0
while q:
    tar = q.popleft()
    step = [(tar[0]+100*a, tar[1]), (tar[0]+100*b, tar[1]),
            (tar[0], tar[1]+c), (tar[0], tar[1]+d)]
    for i in step:
        if i not in used:
            used.add(i)
            if judgement(i[0], i[1]):
                q.append(i)
                if per*i[0] < i[1]:
                    per = i[1]/i[0]
                    ans = i
print(ans[0]+ans[1], ans[1])

Submission status: Accepted

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

if a>b:
    a, b = b, a

ans1 = a*100
ans2 = 0

for _a in range(f//(a*100) + 1):
    for _b in range((f - _a*100)//(b*100) + 1):
        
        max_sugar = min(f-(_a+_b)*100, (f-(_a+_b)*100)//100*e)
        
        for _c in range(max_sugar//c + 1):
            for _d in range((max_sugar-c*_c)//d + 1):
                if a*100*_a+b*100*_b+c*_c+d*_d == 0:
                    continue                
                if a*100*_a+b*100*_b+c*_c+d*_d > f:
                    break 
                    
                if (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) == e/(100+e):
                    print(a*100*_a+b*100*_b+c*_c+d*_d, c*_c+d*_d)
                    sys.exit(0)
                elif (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) > e/(100+e):
                    continue
                else:
                    if ans2/ans1 < (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d):
                        ans1 = a*100*_a+b*100*_b+c*_c+d*_d
                        ans2 = c*_c+d*_d


else:
    print(ans1, ans2)

Submission status: Accepted

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

if a>b:
    a, b = b, a

ans1 = a*100
ans2 = 0

for _a in range(f//(a*100) + 1):
    for _b in range((f - _a*100)//(b*100) + 1):
        
        max_sugar = min(f-(_a+_b)*100, (f-(_a+_b)*100)//100*e)
        
        for _c in range(max_sugar//c + 1):
            for _d in range((max_sugar-c*_c)//d + 1):
                if a*100*_a+b*100*_b+c*_c+d*_d == 0:
                    continue                
                if a*100*_a+b*100*_b+c*_c+d*_d > f:
                    continue  
                    
                if (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) == e/(100+e):
                    print(a*100*_a+b*100*_b+c*_c+d*_d, c*_c+d*_d)
                    sys.exit(0)
                elif (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) > e/(100+e):
                    continue
                else:
                    if ans2/ans1 < (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d):
                        ans1 = a*100*_a+b*100*_b+c*_c+d*_d
                        ans2 = c*_c+d*_d


else:
    print(ans1, ans2)

Submission status: Accepted

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

if a>b:
    a, b = b, a

ans1 = a*100
ans2 = 0

for _a in range(f//(a*100) + 1):
    for _b in range((f - _a*100)//(b*100) + 1):
        for _c in range((f - _a*100 - _b*100)//c + 1):
            for _d in range((f - _a*100 - _b*100 - _c * c)//d + 1):
                if a*100*_a+b*100*_b+c*_c+d*_d == 0:
                    continue                
                if a*100*_a+b*100*_b+c*_c+d*_d > f:
                    continue  
                    
                if (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) == e/(100+e):
                    print(a*100*_a+b*100*_b+c*_c+d*_d, c*_c+d*_d)
                    sys.exit(0)
                elif (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) > e/(100+e):
                    continue
                else:
                    if ans2/ans1 < (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d):
                        ans1 = a*100*_a+b*100*_b+c*_c+d*_d
                        ans2 = c*_c+d*_d
else:
    print(ans1, ans2)

Submission status: Accepted

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

if a>b:
    a, b = b, a

ans1 = a*100
ans2 = 0
    
flag = True

for _a in range(f//(a*100) + 1):
    for _b in range((f - _a*100)//(b*100) + 1):
        for _c in range((f - _a*100 - _b*100)//c + 1):
            for _d in range((f - _a*100 - _b*100 - _c * c)//d + 1):
                if a*100*_a+b*100*_b+c*_c+d*_d == 0:
                    continue                
                if a*100*_a+b*100*_b+c*_c+d*_d > f:
                    continue  
                    
                if (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) == e/(100+e):
                    print(a*100*_a+b*100*_b+c*_c+d*_d, c*_c+d*_d)
                    flag = False
                    break
                elif (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d) > e/(100+e):
                    continue
                else:
                    if ans2/ans1 < (c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d):
                        ans1 = a*100*_a+b*100*_b+c*_c+d*_d
                        ans2 = c*_c+d*_d
            if flag:
                continue
            else:
                break
        if flag:
            continue
        else:
            break
    if flag:
        continue
    else:
        break

else:
    print(ans1, ans2)

Submission status: Accepted

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

    maxConcentration = 0
    resSugarWater = 0
    resSugar = 0

    for i in range(31):
        for j in range((29 * a * i // b) + 1):
            water = (i * a + j * b) * 100
            possibleSugar = int(min(f - water, water * e / 100))
            for k in range((possibleSugar // c) + 1):
                for l in range(((possibleSugar - k * c) // d) + 1):
                    sugar = k * c + l * d

                    if water + sugar > f:
                        break

                    if water + sugar == 0:
                        continue

                    concentration = 100 * sugar / (water + sugar)

                    if concentration >= maxConcentration:
                        maxConcentration = concentration
                        resSugarWater = water + sugar
                        resSugar = sugar
    
    print(resSugarWater, resSugar)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

# ABが水、CDが砂糖、Eがとけられる量、Fが上限
A, B, C, D, E, F = getNM()

# A,Bを好きな回数使うことでi(0 <= i <= 30)の水を作り出せる
dp1 = [0] * 31
dp1[0] = 1
for i in range(1, 31):
    if i >= A:
        dp1[i] = max(dp1[i], dp1[i - A])
    if i >= B:
        dp1[i] = max(dp1[i], dp1[i - B])
waterlist = []
for i in range(31):
    if dp1[i] > 0:
        waterlist.append(i)

# C,Dを好きな回数使うことでi(0 <= i <= 3000)の砂糖を作り出せる
dp2 = [0] * 3001
dp2[0] = 1
for i in range(1, 3001):
    if i >= C:
        dp2[i] = max(dp2[i], dp2[i - C])
    if i >= D:
        dp2[i] = max(dp2[i], dp2[i - D])
sugerlist = []
for i in range(3001):
    if dp2[i] > 0:
        sugerlist.append(i)

ans = [0, 0]
concent = 0

for water in waterlist[1:]:
    if 100 * water <= F:
        left = F - (water * 100)
        # Fから水をひいた分、溶ける砂糖の限界を超えない量の砂糖を取得する
        index = bisect_right(sugerlist, min(left, E * water))
        suger = sugerlist[index - 1]
        # 濃度計算
        optconc = (100 * suger) / (100 * water + suger)
        # ここ>にすると濃度0%に対応できずWAに
        if optconc >= concent:
            concent = optconc
            ans = [100 * water + suger, suger]
print(*ans)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

# ABが水、CDが砂糖、Eがとけられる量、Fが上限
A, B, C, D, E, F = getNM()

dp1 = [0] * 31
dp1[0] = 1
for i in range(1, 31):
    if i >= A:
        dp1[i] = max(dp1[i], dp1[i - A])
    if i >= B:
        dp1[i] = max(dp1[i], dp1[i - B])
waterlist = []
for i in range(31):
    if dp1[i] > 0:
        waterlist.append(i)

dp2 = [0] * 3001
dp2[0] = 1
for i in range(1, 3001):
    if i >= C:
        dp2[i] = max(dp2[i], dp2[i - C])
    if i >= D:
        dp2[i] = max(dp2[i], dp2[i - D])
sugerlist = []
for i in range(3001):
    if dp2[i] > 0:
        sugerlist.append(i)

ans = [0, 0]
concent = 0

for water in waterlist[1:]:
    if 100 * water <= F:
        left = F - (water * 100)
        index = bisect_right(sugerlist, min(left, E * water))
        suger = sugerlist[index - 1]
        optconc = (100 * suger) / (100 * water + suger)
        if optconc >= concent:
            concent = optconc
            ans = [100 * water + suger, suger]
print(*ans)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
a = 100 * A
b = 100 * B
waters = set()
sugers = set()
for i in range(F // a + 1):
    ai = a * i
    f = F - ai
    for j in range(f // b + 1):
        g = ai + b * j
        if g <= F:
            waters.add(g)
for i in range(F // C + 1):
    ci = C * i
    f = F - ci
    for j in range(f // D + 1):
        g = ci + D * j
        if g <= F:
            sugers.add(g)

waters = sorted(waters)
sugers = sorted(sugers)

ans_sum = 100 * A
ans_sg = 0
concetration = 0
for w in waters:
    for s in sugers:
        g = w + s
        if g == 0 or g > F:
            break
        if s > w // 100 * E:
            break
        c = s / g
        if concetration < c:
            concetration = c
            ans_sum = g
            ans_sg = s
print(ans_sum, ans_sg)

Submission status: Accepted

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

water = set()
for i in range(f//(100*a)+1):
    for j in range(f//(100*b)+1):
        g = 100*a*i+100*b*j
        if g <= f and g != 0:
            water.add(g)

max_con = 0
max_water = min(100*a,100*b)
max_suger = 0

for w in water:
    suger = set()
    for i in range((f-w)//c+1):
        for j in range((f-w)//d+1):
            if i*c+j*d <= f-w:
                suger.add(i*c+j*d)
    for s in suger:
        if w//100*e >= s:
            con = 100*s/(w+s)
            if con > max_con:
                max_con = con
                max_water = w
                max_suger = s

print(max_water+max_suger,max_suger)

Submission status: Accepted

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

Submission status: Accepted

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

X, Y = [], []
for i in range(int(f / 100 + 0.9)):
    for j in range(int(f / 100 + 0.9)):
        x = 100 * a * i + 100 * b * j
        if x <= f:
            X.append(x)

for i in range(int(f / c + 0.9)):
    for j in range(int(f / d + 0.9)):
        y = c * i + d * j
        if y <= f:
            Y.append(y)

X = list(set(X))
Y = list(set(Y))

res = [0, 0]
p = e / (100 + e) # 最大濃度
maxP = 0 # ありうる最大濃度
for x in X:
    for y in Y:
        if x + y > 0 and x + y <= f: # 質量制約
            if y / (x + y) <= p: # 溶けるかどうか
                # res.append([x, y])
                if y / (x + y) >= maxP:
                    res[0] = x + y
                    res[1] = y
                    maxP = y / (x + y)
    
print(*res)

Submission status: Accepted

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

ans=[0,0]
concentration=0.0
for i in range(F//(100*B)+1):
    tmp_water=100*B*i
    for j in range((F-tmp_water)//(100*A)+1):
        tmp_water+=100*A*j
        max_suger=min((tmp_water//100)*E,F-tmp_water)
        for k in range((max_suger)//D+1):
            tmp_suger=D*k
            tmp_suger+=C*((max_suger-tmp_suger)//C)
            if tmp_water+tmp_suger==0:
                continue
            elif tmp_suger/(tmp_water+tmp_suger)>=concentration:
                concentration=tmp_suger/(tmp_water+tmp_suger)
                ans[0]=tmp_water+tmp_suger
                ans[1]=tmp_suger

print(*ans)

Submission status: Accepted

Solution code:
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 * a * i) // (100 * b) + 1):
        if 100 * a * i + 100 * b * j <= f:
            water.add(100 * a * i + 100 * b * j)

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

ans = (0, 0)
concentration = 0
for w in water:
    if w == 0:
        continue
    for s in sugar:
        if w + s <= f:
            if concentration <= s / (w + s) <= e / (100 + e):
                concentration = s / (w + s)
                ans = (w + s, s)

print(*ans)

Submission status: Accepted

Solution code:
"""
・ビーカーの総重量がFを超えないように
・ビーカー内に砂糖の溶け残りが出ないように（水100gに対しEg溶ける）
・できるだけ濃度の高い砂糖水を作る
この砂糖水の全質量と砂糖の量を答える

操作は
・水を　100*A or 100*B 追加
・砂糖を　C or D 追加

愚直に考えると、
（１）砂糖水の集合がある。これから一つ取り出して、
（２）水（100A or 100B）、砂糖（C or D）のいずれかを加える。行える操作は全部試すので、4通りに分岐
（３）溶け残りやFを超えるなどした場合は除外する
（４）（３）の判定を通過した各砂糖水に対し、これまでに作った砂糖水より濃度が大きければ、答えとして更新する
（５）（４）で評価した砂糖水を（１）の集合に戻す
のように、ありえるパターンを全部試す。
CやDが小さいと間に合わないはず。重複ができたりするとしんどい。

容器の最大容量Fが <=3000と小さい。
なので、今回は先に作れる水の重量を全探索で作っておいて、それらに砂糖を入れられるだけ入れる、の方法でやると、
水の操作と砂糖の操作を独立に行えるので、計算量を減らせる。
砂糖も初めに全探索で、何gのができるか全部つくっておいて、水と全部の組み合わせを試して～みたいな感じにしてもいいかも。
ビーカーが3000までなので、最大でも3000*3000の組み合わせなので、間に合いそう
"""

from collections import deque


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):
        if 100*A*i + 100*B*j > F:
            continue
        waters.add(100*A*i + 100*B*j)

sugars = set()
for i in range(F // C + 1):
    for j in range((F - C*i) // D + 1):
        if C*i + D*j > F:
            continue
        sugars.add(C*i + D*j)


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

ans = [0.0, 100*A, 0]

for w in waters:
    if w == 0:
        continue
    for s in sugars:
        if w+s > F:
            break
        if s / (w+s+0.0) > E / (E + 100.0):
            break
        
        if s / (w+s) > ans[0]:
            ans = [s / (w+s+0.0), w+s, s]

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

Submission status: Accepted

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

w_list = []
s_list = []
d_list = []

for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                w = (100 * A) * a + (100 * B) * b
                s = C * c + D * d
                if w == 0 or w + s > F:
                    break
                else:
                    if w // 100 * E >= s:
                        d = s / (w + s)
                        w_list.append(w)
                        s_list.append(s)
                        d_list.append(d)

print(w_list[d_list.index(max(d_list))] + s_list[d_list.index(max(d_list))], s_list[d_list.index(max(d_list))])

Submission status: Accepted

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

max_concentration = 0
max_sugar = 0
max_sugar_water = 0
for a in range(31):
    if a * 100 * A > F:
        continue
    for b in range(31):
        if 100 * A * a + 100 * B * b > F:
            continue
        for c in range(3000 // C + 1):
            if E * (a * A + b * B) < c * C:
                continue
            if 100 * A * a + 100 * B * b + c * C > F:
                continue
            d = (E * (a * A + b * B) - c * C) // D
            if a * 100 * A + b * 100 * B + c * C + d * D == 0:
                continue
            if a * 100 * A + b * 100 * B + c * C + d * D > F:
                d = (F - (a * 100 * A + b * 100 * B + c * C)) // D
            tmp_sugar_water = a * 100 * A + b * 100 * B + c * C + d * D
            tmp_sugar = c * C + d * D
            tmp_concentration = tmp_sugar / tmp_sugar_water
            if max_concentration <= tmp_concentration:
                max_concentration = tmp_concentration
                max_sugar_water = tmp_sugar_water
                max_sugar = tmp_sugar
print(max_sugar_water, max_sugar)

Submission status: Accepted

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

memo = {}

for x in range(31):
    for y in range(31):
        for s in range(101):
            for t in range(101):
                water = (100*a)*x + (100*b)*y
                sugar = s*c + t*d
                if water == 0:
                    break
                if water + sugar > f:
                    break
                else:
                    if water/100 * e >= sugar:
                        density = 100*sugar/(water + sugar)
                        memo[x, y, s, t] = density

max_v = max(memo.values())

for k, v in memo.items():
    if v == max_v:
        print((100*a)*k[0] + (100*b)*k[1] + c*k[2] + d*k[3], c*k[2] + d*k[3])
        break

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

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

    w = set()
    for i in range(int(F/A/100)+1):
        for j in range(int(F/B/100)+1):
            if 0 < A*i+B*j <= int(F/100):
                w.add((A*i+B*j)*100)
    s = set()
    for i in range(int(F*E/(100+E)/C)+1):
        for j in range(int(F*E/(100+E)/D)+1):
            if 0 <= C*i+D*j <= int(F*E/(100+E)):
                s.add(C*i+D*j)

    max_E = -1.0
    ans_w = 0
    ans_s = 0
    for x in w:
        for y in s:
            if x + y <= F and y <= x/100 * E and max_E < y/(x+y) * 100:
                max_E = y/(x+y) * 100
                ans_w = x + y
                ans_s = y
    print(ans_w,ans_s)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def dense(w, s):
	if w + s == 0:
		return 0
	return s / (w + s)

def resolve():
	a, b, c, d, e, f = map(int, input().split())
	water_set = set()
	sugar_set = set()
	for i in range(31):
		for j in range(31):
			s = 100*a*i + 100*b*j
			if s <= f:
				water_set.add(100*a*i + 100*b*j)
	for i in range(1001):
		for j in range(1001):
			s = i*c + j*d
			if s <= f:
				sugar_set.add(s)
	wv, sv = 0, 0
	for w in water_set:
		for s in sugar_set:
			if f < (w + s) or (w//100*e) < s:
				continue
			if dense(wv, sv) <= dense(w, s):
				wv, sv = w, s
	print(wv+sv, sv)
resolve()

Submission status: Accepted

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

d = 0
for i in range(31):
    if i * 100 * A > F:
        break
    for j in range(31):
        if i * 100 * A + j * 100 * B > F:
            break
        if i == 0 and j == 0:
            break
        for k in range(0, 1501, C):
            if k > i * A * E + j * B * E:
                break
            m = i * 100 * A + j * 100 * B + k
            if m > F:
                break
            l1 = F - m
            l2 = i * A * E + j * B * E - k
            l = min(l1, l2)
            l = int(l / D) * D
            d1 = 100 * (k + l) / (m + l)
            if d < d1:
                w = m + l
                s = k + l
                d = d1
if d == 0:
    if 100 * A <= F:
        print('{0} {1}'.format(100 * A, 0))
    else:
        print('{0} {1}'.format(100 * B, 0))
else:
    print('{0} {1}'.format(w, s))

Submission status: Accepted

Solution code:
a,b,x,y,s,m = map(int,input().split())

#a,b,x,y,s,m = (1,2,1,2,100,1000)
a *= 100
b *= 100

#入れられる水の候補
waterlist=[]
amax = int(m/a)
for i in range(amax+1):
  bmax = int((m-a*i)/b)
  for j in range(bmax+1):
    water = a*i + b*j
    if water:
      waterlist.append(a*i + b*j)
waterlist = set(waterlist)

#砂糖の組み合わせから最大を
def makesatolist(maxsato,x,y):
  satolist = []
  xmax = int(maxsato/x)
  for i in range(xmax+1):
    ymax  = int((maxsato-x*i)/y)
    for j in range(ymax+1):
      satolist.append(x*i + y*j)
  return max(satolist)
  
nownodo = 0
ans = [0] * 2
for i in waterlist:
 
  # iグラムの水に何グラムの砂糖まで解ける？
  maxsato = i * s/100
  if i + maxsato > m:
    maxsato = m - i

  sato = makesatolist(maxsato,x,y)
  satowater = i + sato
  nodo = sato / satowater
  if nodo >= nownodo:
    nownodo = nodo
    ans = [satowater,sato]

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

Submission status: Accepted

Solution code:
def main():
    from itertools import combinations
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100

    water = [a * i + b * j for i in range(f // a + 1) for j in range(f // b + 1)]
    sugar = [c * i + d * j for i in range(f // c + 1) for j in range(f // d + 1)]
    water.sort()
    sugar.sort(reverse=True)

    tmp = 0
    x, y = 0, 0
    for w in water:
        if w == 0:
            continue
        for s in sugar:
            if s + w > f:
                continue
            if s * 100 <= e * w and tmp <= s / (s + w):
                tmp = s / (s + w)
                x = s + w
                y = s
    print(x,y)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def maxValue(a,b,v):
	for i in range(v,-1,-1):
		for j in range(v//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i

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

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa == 0:
		break
	if maxR<10000*suVa//(suVa+waVa):
		maxR = 10000*suVa//(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Submission status: Accepted

Solution code:
def maxValue(a,b,v):
	for i in range(v,-1,-1):
		for j in range(v//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i

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

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa == 0:
		break
	if maxR<100*suVa/(suVa+waVa):
		maxR = 100*suVa/(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Submission status: Accepted

Solution code:
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i

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

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa == 0:
		break
	if maxR<100*suVa/(suVa+waVa):
		maxR = 100*suVa/(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Submission status: Accepted

Solution code:
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

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

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa == 0:
		break
	if maxR<100*suVa/(suVa+waVa):
		maxR = 100*suVa/(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Submission status: Accepted

Solution code:

def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

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

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa == 0:
		break
	if maxR<100*suVa/(suVa+waVa):
		maxR = 100*suVa/(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Submission status: Accepted

Solution code:
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1

def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				#print(j,k//b)
				return i
	return -1

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

waVa = maxValue(a*100,b*100,f)
suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
maxR = 0

anw = waVa
ans = suVa

while 1:
	waVa = maxValue(a*100,b*100,waVa-1)
	suVa = maxValue(c,d,min(f-waVa,waVa*e//100))
	if waVa<0 or suVa<0:
		continue
	if waVa == 0:
		break
	if maxR<100*suVa/(suVa+waVa):
		maxR = 100*suVa/(suVa+waVa)
		anw = waVa
		ans = suVa

print(anw+ans,ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().strip().split(" "))
a = 100 * a
b = 100 * b
e = e * 100 / (100.0+e)

water = set([])
for i in range((f+a)//a):
    for j in range((f+b)//b):
        w = a * i + b * j
        if w <= f and 0 < w:
            water.add(a * i + b * j)


sugar = set([])
for i in range((f+c)//c):
    for j in range((f+d)//d):
        s = c * i + d * j
        if s <= f:
            sugar.add(c * i + d * j)
density = -1
_s = 0
sw = 0
for w in water:
    for s in sugar:
        _d = 100 * s / (s+w)
        if _d <= e and w + s <= f and density < _d:
            density = _d
            sw = w + s
            _s = s

print(sw, _s)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int,input().split())
wa = []
for ia in range(30):
    for ib in range(30):
        if 100*(ia*a+ib*b) <= f and not 100*(ia*a+ib*b) in wa:
            wa.append(ia*a+ib*b)

msu = [0 for i in range(len(wa))]
mc = -0.01
mci = -1
for i,w in enumerate(wa):
    for ic in range(1501):
        for id in range(1501):
            if ic*c+id*d > e*w:
                break
            if ic*c+id*d+w*100 > f:
                break
            if msu[i] < ic*c+id*d:
                msu[i] = ic*c+id*d
                if mc < (ic*c+id*d)/(ic*c+id*d+w*100):
                    mc = (ic*c+id*d)/(ic*c+id*d+w*100)
                    mci = i

print(wa[mci]*100+msu[mci],msu[mci])