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 = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar)//c + 1):
            for dt in range(0, (maxsugar-ct*c)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar+1)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = 100 * sugar / water
                    if n == e:
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Submission status: Accepted

Solution code:
from decimal import Decimal
a,b,c,d,e,f = list(map(int, input().split()))
maxn = -1
ans = ()
for at in range(0,31):
    for bt in range(0,31-at):
        water = (at * a + bt * b) * 100
        if water > f:
            continue

        # 溶け残らないように砂糖を選ぶ
        maxsugar = water * e // 100
        for ct in range(0, (maxsugar+1)//c + 1):
            for dt in range(0, (maxsugar-ct*c+1)//d + 1):
                sugar = ct * c + dt * d

                if 0 < sugar + water <= f and sugar <= (at * a + bt * b) * e:
                    # 水１００に対して溶けている砂糖の量
                    n = Decimal(100 * sugar / water)
                    if n == Decimal(e):
                        print(water + sugar, sugar)
                        exit()
                    if n > maxn:
                        ans = water + sugar, sugar
                        maxn = n
print(*ans)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
perc = 0.0
ans = [0, 0]
op = [0, 0, 0, 0]
a = 0
while 100 * a <= F:
  b = 0
  while 100 * (a + b) <= F:
    c = 0
    while 100 * (a + b) + c <= F:
      if c > (a + b) * E:
        break
      d = 0
      while 100 * (a + b) + c + d <= F:
        if c + d > (a + b) * E:
          break
        if a == b == c == d == 0:
          break
        p = (c + d) * 1.0 / (100 * (a + b) + c + d)
        if p >= perc:
          perc = p
          ans = [100 * (a + b) + c + d, c + d]
          op = [a, b, c, d]
        d += D
      c += C
    b += B
  a += A
print(str(ans[0]) + " " + str(ans[1]))

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
noudo=0
water=[]
for i in range(31):
  for j in range(31):
    w=100*A*i+100*B*j
    if w<=F and w!=0:
      water.append(w)
sugar=[]
for i in range(F//C+1):
  for j in range(F//D+1):
    w=C*i+D*j
    if w<=F:
      sugar.append(w)
ans1=0
ans2=0
for i in range(len(water)):
  for j in range(len(sugar)):
    if water[i]+sugar[j]<=F:
      if sugar[j]/water[i]<=E/100:
        if noudo<sugar[j]/water[i]:
          ans1=sugar[j]+water[i]
          ans2=sugar[j]
          noudo=sugar[j]/water[i]
if ans2==0:
  print(water[0],0)
else:
  print(ans1,ans2)

Submission status: Accepted

Solution code:
from math import gcd
a,b,c,d,e,f=map(int,input().split())
g=gcd(a,b)
a=a//g
b=b//g
G=gcd(c,d)
c=c//G
d=d//G
axby=[0]*1000
czdw=[0]*1000
for x in range(100):
    for y in range(100):
        if a*x+b*y<(a-1)*(b-1):
            axby[a*x+b*y]=1
for z in range(100):
    for w in range(100):
        if c*z+d*w<(c-1)*(d-1):
            czdw[c*z+d*w]=1
A=[]
C=[]
for i in range(1000):
    if axby[i]==1:
        A.append(i)
for i in range(1000):
    if czdw[i]==1:
        C.append(i)
i=(a-1)*(b-1)
while i<=(f//(100*g))+5:
    A.append(i)
    i+=1
j=(c-1)*(d-1)
while j<=(f//G)+5:
    C.append(j)
    j+=1
n=len(A)
m=len(C)
dis=0
ans=[0,0]
for i in range(n):
    for j in range(m):
        if 100*g*A[i]+G*C[j]<=f and G*C[j]<=e*g*A[i] and not(A[i]==C[j]==0):
            if dis<=(100*G*C[j])/(100*g*A[i]+G*C[j]):
                dis=(100*G*C[j])/(100*g*A[i]+G*C[j])
                ans[0],ans[1]=A[i],C[j]
print(100*g*ans[0]+G*ans[1],G*ans[1])

Submission status: Accepted

Solution code:
"""
a, b, c, d, e, f = map(int, input().split())
ans = [pow(10, 9), 1]
a *= 100
b *= 100
for w1 in range(31):
    for w2 in range(31):
        water = w1 * a + w2 * b
        if water > f or water == 0:
            continue
        for s1 in range(min(water, 3000 - water)):
            for s2 in range(min(water, 3000 - water)):
                sugar = s1 * c + s2 * d
                if water + sugar > f or e / 100 < sugar / water:
                    break
                if ans[1] / ans[0] <= sugar / (water + sugar):
                    ans = [water + sugar, sugar]
print(ans[0], ans[1])
"""


a, b, c, d, e, f = map(int, input().split())
sugar = [0] * (f + 5)
for i in range(f + 1):
    if i * c > f:
        break
    for j in range(f + 1):
        if i * c + j * d > f:
            break
        sugar[i * c + j * d] = 1
water = [0] * (f // 100 + 5)
for i in range(f // 100 + 1):
    if i * a > f // 100:
        break
    for j in range(f // 100 + 1):
        if i * a + j * b > f // 100:
            break
        water[i * a + j * b] = 1
m = 0
ans1, ans2 = a * 100, 0
for i in range(1, f // 100 + 1):
    if water[i] == 0:
        continue
    t = 0
    for j in range(i * e, 0, -1):
        if sugar[j] == 1:
            if 100 * i + j <= f and m <= 100 * j / (i + j):
                ans1, ans2 = 100 * i + j, j
                m = 100 * j / (i + j)
                t = 1
        if t == 1:
            break
print(ans1, ans2)

Submission status: Accepted

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

nou = [0,100*A]
for a in range(31):
    for b in range(31):
        for c in range(3001):
            if a==0 and b==0:
                continue
            if F<(100*A*a+100*B*b+C*c):
                continue
            if E*(A*a+B*b)<C*c:
                continue
            #abcが決まればdはEとFの上限を超えないギリギリを責めればいい
            d = max(0, (F-(100*A*a+100*B*b+C*c))//D)#Fの条件
            d = min(d,(E*(A*a+B*b)-C*c)//D)

            if nou[0]*((100*A*a+100*B*b)+(C*c+D*d)) < (C*c+D*d)*nou[1]:
                nou = [C*c+D*d,((100*A*a+100*B*b)+(C*c+D*d)),a,b,c,d]

print(nou[1],nou[0])

Submission status: Accepted

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

water = [False] * (f//100 + 1)
for i in range(0, len(water), a):
    water[i] = True
for i in range(len(water) - b):
    if water[i]:
        water[i + b] = True

sugar = [False] * ((f//100) * e + 1)
for i in range(0, len(sugar), c):
    sugar[i] = True
for i in range(len(sugar) - d):
    if sugar[i]:
        sugar[i + d] = True

# denominator: 分母, numerator: 分子
deno = a * 100
nume = 0

for i in range(1, len(water)):
    if water[i]:
        j = min([i*e, f - 100*i])
        while not sugar[j]:
            j -= 1
        i = 100 * i + j

        if nume * i < deno * j:
            deno = i
            nume = j

print(deno, nume)

Submission status: Accepted

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

def reduce(x): #約分
  #print(x)
  d = math.gcd(x[0], x[1])
  return (x[0] // d, x[1] // d)

def is_valid(s, w): #砂糖s、水100w
  return s <= w * E and s + 100*w <= F

ratios = set()
recipe = {}

Waters = [] 
for a in range(0, w_max+1, A):
  for b in range(0, w_max+1, B):
    if (a == 0 and b == 0) or a + b > F:
      continue
    Waters.append(a+b)
Waters.sort()

s_max = 0
for x in Waters:
  s_max = max(s_max, min(x*E,F-100*x))

Sugars = [] 
for c in range(0, s_max+1, C):
  for d in range(0, s_max+1, D):
    Sugars.append(c+d)
Sugars.sort()

i = 0
ascend = True
for w in Waters:
  while i >= 0 and not is_valid(Sugars[i], w):
    i -= 1
  while 0 <= i < len(Sugars) and is_valid(Sugars[i], w):
    i += 1
  i -= 1
  if i >= 0:
    ratios.add(reduce((Sugars[i], w)))
    recipe[reduce((Sugars[i], w))] = (Sugars[i], w)

ans = recipe[max(ratios, key = lambda x: float(x[0]/x[1]))]
print(ans[1]*100 + ans[0], ans[0])

Submission status: Accepted

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

best_dense = -float("inf")
for a in range(31):
    for b in range(31):
        for c in range(1501):
            for d in range(1501):
                w_sum = 100 * A * a + 100 * B * b
                s_sum = C * c + D * d
                sum = w_sum + s_sum
                if sum > F: break
                if w_sum == 0: break
                if E * (w_sum / 100) < s_sum: break
                dense = s_sum / sum
                if dense > best_dense:
                    best_dense = dense
                    ans_sum = sum
                    ans_s_sum = s_sum
print(ans_sum, ans_s_sum)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
max_a = int(3000 / (100 * A))
max_b = int(3000 / (100 * B))
max_c = int(3000 / C)
max_d = int(3000 / D)
max_dens = 0
max_sugar = 0
max_sugar_water = 0
for i in range(max_a + 1):
  water_A = 100 * A * i
  if water_A > F:
    break
  for j in range(max_b + 1):
    water = 100 * B * j + water_A
    if water > F:
      break
    max_solvable_sugar = E * water
    for s in range(max_c + 1):
      sugar_C = C * s
      if sugar_C * 100 > max_solvable_sugar:
        break
      for t in range(max_d + 1):
        sugar = D * t + sugar_C
        if sugar * 100 > max_solvable_sugar:
          break
        sugar_water = water + sugar
        if sugar_water > F or sugar_water == 0:
          break
        dens = 100 * sugar / sugar_water
        if dens >= max_dens:
          max_dens = dens
          max_sugar = sugar
          max_sugar_water = sugar_water
print("{} {}".format(max_sugar_water, max_sugar))

Submission status: Accepted

Solution code:
from itertools import product
A,B,C,D,E,F=map(int, input().split())
ans = -float("inf")
mass = 0
sugarr = 0
for s, t in product(range(0, 31), repeat=2):
    water = 100*(A*s+B*t)
    if water > F or water == 0:
        continue
    up = min(F-water, E*(A*s+B*t))
    for u in range(0, up+1):
        if C*u > up:
            continue
        v = int((up-C*u)/D)
        if v < 0:
            continue
        sugar = C*u+D*v
        cons = sugar/(water+sugar)
        if cons > ans:
            ans = cons
            mass = water + sugar
            sugarr = sugar
print(mass, sugarr)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
dins = -1
suger = 0
ans = 0

for i in range(f//(a*100)+1):
  for j in range(f//(b*100)+1):
    if 100*(i*a+j*b)>f:
      continue
    else:
      water = 100*(i*a+j*b) 
      maxsuger = e*(i*a+j*b)
      for k in range(maxsuger//c+1):
        for l in range(maxsuger//d+1):
          su = k*c+l*d
          if su>maxsuger or (water+su)>f:
            continue
          else:
            if (water+su) != 0:
                nowd = (su/(water+su))*100
                if nowd>dins:
                  suger = su
                  ans = (water+su)
                  dins = nowd
print(ans,suger)

Submission status: Accepted

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

wa=[]
su=[]
for i in range(1,31):
  for j in range(0,31):
    x=i-j*a
    if x>=0:
      if x%b==0:
        wa.append(i*100)
        
for p in range(1,3001):
  for q in range(0,3001):
    y=p-q*c
    if y>=0:
      if y%d==0:
        su.append(p)
        
wa1=list(set(wa))
su1=list(set(su))

ans=0
ans1=[]
for r in wa1:
  for t in su1:
    if r+t<=f and t/r <= e/100:
      if t/(r+t)>=ans:
        ans=t/(r+t)
        ans1.append([r,t])
        
if len(ans1)==0:
  print(str(wa[0])+' '+str(0))
else:
  W=ans1[-1][0]
  S=ans1[-1][1]
  print(str(W+S)+' '+str(S))

Submission status: Accepted

Solution code:
def solve():
    max_density = -1
    ans = [-1, -1]
    A, B, C, D, E, F = map(int, input().split())
    for a in range(0, F + 1, A * 100):
        for b in range(0, F - a + 1, B * 100):
            w = a + b
            if w == 0:
                continue
            max_s = min(F - w, w // 100 * E)
            for c in range(0, max_s + 1, C):
                for d in range(0, max_s - c + 1, D):
                    s = c + d
                    density = 100 * s / (w + s)
                    if density > max_density:
                        ans = [w + s, s]
                        max_density = density
    return ans


print(*solve())

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
s = set()
for i in range(30 // a + 1):
    for j in range(30 // b + 1):
        if 0 < (a * i + b * j) * 100 <= f:
            s = s | {a * i + b * j}
s2 = set()
for i in range(3000 // c + 1):
    for j in range(3000 // d + 1):
        if c * i + d * j <= f:
            s2 = s2 | {c * i + d * j}
ans = []
for i in s:
    for j in s2:
        if i * 100 + j <= f and j <= i * e:
            ans.append([j / i * -1, i * 100 + j, j])
ans.sort()
print(ans[0][1], ans[0][2])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A,B,C,D,E,F = map(int, readline().split())
ans = (100*A,0)
max_con = 0

for a in range(31):
    for b in range(31):
        for c in range(50):
            for d in range(50):
                W = a * 100 * A + b * 100 * B
                S = c*C + d*D
                SW = S + W 
                e = W // 100
                if F < SW or SW == 0:
                    continue
                if e * E < S:
                    continue
                tmp = 100 * S / SW
                if tmp > max_con:
                    max_con = tmp
                    ans = (SW,S)
print(' '.join(str(a) for a in ans))

Submission status: Accepted

Solution code:
from math import gcd

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

N = 0; max_SW = A*100; max_S = 0
f = F//100; a = f//A; b = f//B
cn = D // gcd(C, D)

for j in range(b+1): #Bをj杯入れる
    for i in range(a+1): #Aをi杯入れる
        if i==0 and j==0:
            continue
        elif A*i + B*j > f:
            continue
        w = (A*i + B*j) * 100 #水の量
        e = (A*i + B*j) * E #この場合において溶ける砂糖の最大値
        S = min(e, F-w) #ビーカーも考慮した砂糖を入れられる限界
        s = 0
        for ci in range(min(S//C, cn)+1):
            s = max(s, S - (S - C*ci) % D)
        if s/(w+s) > N:
            N = s/(w+s)
            max_SW = s + w
            max_S = s

print(max_SW, max_S)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=[int(i) for i in input().split()]

max_a=f//(100*a)
max_b=f//(100*b)
max_c=f//c
max_d=f//d

#水リスト
x_list=[]
for i in range(max_a+1):
   for j in range(max_b+1):
        #水
       x=100*a*i+100*b*j
       if 0<x<=f and x not in x_list:
           x_list.append(x)
#print(x_list)
       
#砂糖リスト
y_list=[]
for i in range(max_c+1):
   for j in range(max_d+1):
        #砂糖
       y=c*i+d*j
       if 0<=y<f and y not in y_list:
           y_list.append(y)
#print(y_list)

concentration_list=[]
sugar_water_list=[]
sugar_list=[]

for i in x_list:
   for j in y_list:
       if i+j<=f and j/i<=e/100:
           concentration=100*j/(i+j)
           concentration_list.append(concentration)
           sugar_water_list.append(i+j)
           sugar_list.append(j)
                   
sugar_index=concentration_list.index(max(concentration_list))
print(sugar_water_list[sugar_index],sugar_list[sugar_index])

Submission status: Accepted

Solution code:
import bisect, heapq

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

w = set()
temp = [a * i for i in range((30 - 1) // a + 2)]
for i in temp:
    while i not in w and i <= 30:
        w.add(i)
        i += b
w = list(w)
w.remove(0)
w.sort()

s = set()
temp = [c * i for i in range((3000 - 1) // c + 2)]
for i in temp:
    while i not in s and i <= 3000:
        s.add(i)
        i += d
s = list(s)
s.sort()

queue = []
heapq.heapify(queue)
for i in w:
    if i * 100 > f:
        continue
    num = bisect.bisect(s, i * e)
    for j in range(num - 1, -1, -1):
        if i * 100 + s[j] > f:
            continue
        heapq.heappush(queue, [-s[j] / i, 100 * i + s[j], s[j]])
        break
print(queue[0][1], queue[0][2])

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
s = [0,0,0,0]
con1 = 0
for x in range(31):
    for y in range(31):
        for v in range(1501):
            if x == y == 0:
                continue
            else:
                w1 = (f-(100*a*x + 100*b*y + c*v))//d
#                 w2 = (100*a*x + 100*b*y -c*v)//d
                w3 = ((100*a*x + 100*b*y)*e -c*v*100)//(100*d)
                w = min(w1,w3)
                con2 = 100*(c*v + d*w)/(100*a*x + 100*b*y +c*v +d*w)
                if con1 <= con2 and w >= 0:
                    con1 = con2
                    s = [x,y,v,w]
                else:
                    continue

ans1 = 100*a*s[0] + 100*b*s[1] + c*s[2] + d*s[3]
ans2 = c*s[2] + d*s[3]
print(ans1,ans2)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
s = [0,0,0,0]
con1 = 0
for x in range(31):
    for y in range(31):
        for v in range(1501):
            if x == y == 0:
                continue
            else:
                w1 = (f-(100*a*x + 100*b*y + c*v))//d
                w2 = (100*a*x + 100*b*y -c*v)//d
                w3 = ((100*a*x + 100*b*y)*e -c*v*100)//(100*d)
                w = min(w1,w2,w3)
                con2 = 100*(c*v + d*w)/(100*a*x + 100*b*y +c*v +d*w)
                if con1 <= con2 and w >= 0:
                    con1 = con2
                    s = [x,y,v,w]
                else:
                    continue

ans1 = 100*a*s[0] + 100*b*s[1] + c*s[2] + d*s[3]
ans2 = c*s[2] + d*s[3]
print(ans1,ans2)

Submission status: Accepted

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

CCT = {}
#可能な操作を全探索
for a in range(F//(100*A) +1): #Aをa回
    for b in range((F-a*A*100)//(100*B) +1): #Bをb回
        water = (a*A+b*B)*100
        max_suger = water*E//100
        for c in range(max_suger//C +1): #Cをc回
            for d in range((max_suger-c*C)//D +1): #Dをd回
                suger = c*C+d*D
                total = water + suger
                if total > F or total == 0 or max_suger < suger:
                    continue
                CCT[water,suger] = suger/total

ans = (A*100, 0)
max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = (water+suger, suger)
print(*ans)

Submission status: Accepted

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

CCT = {}
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        water = (a*A+b*B)*100
        if water > F:
            continue
        max_suger = water*E//100
        for c in range(max_suger//C+1):
            for d in range((max_suger-c*C)//D+1):
                suger = c*C+d*D
                total = water + suger
                if total > F or total == 0 or max_suger < suger:
                    continue
                CCT[water,suger] = suger/total

ans = (A*100, 0)
max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = (water+suger, suger)
print(*ans)

Submission status: Accepted

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

CCT = {}
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        water = (a*A+b*B)*100
        if water > F:
            continue
        max_suger = water*E//100
        for c in range(max_suger//C+1):
            for d in range(max_suger//D+1):
                suger = c*C+d*D
                total = water + suger
                if total > F or total == 0:
                    continue
                if max_suger < suger:
                    continue
                CCT[water,suger] = suger/total

ans = (A*100, 0)
max_cct = 0
for (water,suger),cct in CCT.items():
    if cct > max_cct:
        max_cct = cct
        ans = (water+suger, suger)
print(*ans)

Submission status: Accepted

Solution code:
import sys
water1,water2,sugar1,sugar2,per_limit,total_limit = map(int,input().split())

max_sugar_per_water = 0
best_total = 0
best_sugar = 0
# waterはfor使うか、、、

if per_limit == 0:
    print(100*water1)
    sys.exit()

for time_water1 in range(30):
    for time_water2 in range(30):
        water = water1*time_water1*100 + water2*time_water2*100
        if water > total_limit:
            break
        if water == 0:
            continue

        sugar_limit = (water//100)*per_limit
        time_sugar1 = 0
        while True:
            time_sugar2 = 0
            while True:
                sugar = sugar1*time_sugar1+sugar2*time_sugar2

                # トータルの重さ判定
                if total_limit < water+sugar:
                    break
                # 溶ける量制限判定
                if sugar_limit < sugar:
                    break

                # 濃度求めて、最大なら更新
                sugar_per_water = sugar/water
                if sugar_per_water >= max_sugar_per_water:
                    max_sugar_per_water = sugar_per_water
                    best_sugar = sugar
                    best_total = sugar+water

                # 砂糖2の量を更新
                time_sugar2 += 1

            # 砂糖1だけで制限超過してたらbreak
            if sugar1*time_sugar1 > sugar_limit or sugar1*time_sugar1 + water > total_limit:
                break
            # 砂糖1を更新
            time_sugar1 += 1

        if water > total_limit:
            break
print(best_total,best_sugar)

Submission status: Accepted

Solution code:
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy

def solve():
    a, b, c, d, e, f = getList()
    dp = [[0 for i in range(f+1)] for j in range(f+1)]
    dp[0][0] = 1
    for i in range(f):
        for j in range(f):
            if dp[i][j] == 1:
                if i + a * 100 <= f:
                    dp[i+a*100][j] = 1
                if i + b * 100 <= f:
                    dp[i+b*100][j] = 1
                if i + c <= f:
                    dp[i+c][j+c] = 1
                if i + d <= f:
                    dp[i+d][j+d] = 1

    ans = (a*100, 0)

    for i in range(1, f+1):
        for j in range(f+1):
            if dp[i][j] == 1:
                if e * (i-j) / 100 >= j:
                    if ans[1]/ans[0] < j/i:
                        ans = (i, j)


    print(*ans)





def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

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

x, y = a, 0  
conc_best = 0

for i in range(f // a + 1):
    for j in range(((f - a * i) // b) + 1):
        water = i * a + j * b
        if water == 0:
            continue
        rest = f - water
        sug_max = e * water / 100
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                conc = sugar / (sugar + water)

                if sugar <= sug_max and conc> conc_best:
                        conc_best = conc
                        x, y = sugar+water , sugar
print(x, y)

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
conc = 0
sug_max = 0 
conc_best = 0
sug_best = 0 
sug_wat_best = 0

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
            conc = sug/(sug+k)*100
            if 0<= sug <= sug_max and k+sug <= f and conc_best <= conc :
                conc_best = conc
                sug_wat_best = sug + k
                sug_best = sug
print(sug_wat_best, sug_best)