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())
W, S = 0, 0
conc = 0

for a in range(0, F+1, 100):
    a *= A
    for b in range(0, F+1, 100):
        b *= B
        water = a+b
        if water == 0 or water > F:
            break
        limit = water/100 * E

        for c in range(100):
            c *= C
            if c > limit or water+c > F:
                break

            for d in range(100):
                sugar = c + d*D
                if sugar > limit or water+sugar > F:
                    break
                tmp = 0
                if sugar != 0:
                    tmp = 100*sugar / (water+sugar)
                if tmp >= conc:
                    conc = tmp
                    W = water
                    S = sugar

print(W+S, S)

Submission status: Accepted

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

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

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

for i in water:
    for j in sugar:
        if 0 < i + j <= F and j / (i + j) <= E / (100 + E):
            sugar_water.append([i + j, j])

max_sugar_water = max(sugar_water, key=lambda x: x[1] / x[0])
print("{} {}".format(max_sugar_water[0], max_sugar_water[1]))

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
water=[]
for i in range(1+30//a):
  for j in range(1+30//b):
    hoge=a*i*100+b*j*100
    if(hoge<=f):
      water.append(hoge)
water=list(set(water))
      
sugar=[]
for i in range(1+3000//c):
  for j in range(1+3000//d):
    hoge=c*i+d*j
    if(hoge<=f):
      sugar.append(hoge)
sugar=list(set(sugar))

node_max=0
water_max=0
sugar_max=0
for i in range(len(water)):
  for j in range(len(sugar)):
    if(water[i]+sugar[j]<=f):
      if(sugar[j]==0):
        node=0
      else:
        node=sugar[j]/(water[i]+sugar[j])
      if(node_max<=node and e*water[i]//100>=sugar[j]):
        water_max=water[i]
        sugar_max=sugar[j]
        node_max=node

print(water_max+sugar_max,sugar_max)

Submission status: Accepted

Solution code:
A, B, C, D, E, F =  map(int, input().split())
M = 0
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:
			break
		for k in range((F - w) // C + 1):
			for l in range((F - w - C * k) // D + 1):
				s = C * k + D * l
				if E >= 100 * s / w and 100 * s / w >= M:
					M = 100 * s / w
					X = [w + s, s]
print(X[0], X[1])

Submission status: Accepted

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

dens=0
a=F//100//A
b=F//100//B
c=F//C
d=F//D
for i in range(a+1):
  for j in range(b+1):
    waterA=100*i*A
    waterAB=waterA+100*j*B
    if  waterA<= F and 0 < waterAB <= F:
      for k in range(c+1):
        for l in range(d+1):
          if waterAB+k*C+l*D <= F:
            if k*C+l*D <= (i*A+j*B)*E:
              if dens < (k*C+l*D)/(waterAB+k*C+l*D):
                dens=(k*C+l*D)/(waterAB+k*C+l*D)
                max1=waterAB+k*C+l*D
                max2=k*C+l*D
            else:
              max3=waterAB
              max4=0
if dens>0:
  print(max1,max2)
else:
  print(max3,max4)

Submission status: Accepted

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

dens=0
for a in range(30+1):
  for b in range(30+1):
    waterA=100*a*A
    waterAB=waterA+100*b*B
    if  waterA<= F and 0 < waterAB <= F:
      for c in range(100+1):
        for d in range(100+1):
          if waterAB+c*C+d*D <= F:
            if c*C+d*D <= (a*A+b*B)*E:
              if dens < (c*C+d*D)/(waterAB+c*C+d*D):
                dens=(c*C+d*D)/(waterAB+c*C+d*D)
                max1=waterAB+c*C+d*D
                max2=c*C+d*D
            else:
              max3=waterAB
              max4=0
if dens>0:
  print(max1,max2)
else:
  print(max3,max4)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(31):
    for b in range(31):
        if not a == b == 0 and a*A*100 + b*B*100 <= F:
            for c in range(int((F - a*A*100 + b*B*100) / C) + 1):
                for d in range(int((F - a*A*100 + b*B*100 + c*C) / D) + 1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if (c*C+d*D)/(100*a*A+100*b*B+c*C+d*D) <= E/(100+E):
                            if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                                con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                                sugar = c*C+d*D
                                sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
con = 0
sugar_water = 0
sugar = 0
for a in range(int(F / 100 / A) + 1):
    for b in range(int((F - a * 100 * A)/ 100 / B) + 1):
        if not a == b == 0:
            for c in range(int((a*A+b*B)*E/C)+1):
                for d in range(int(((a*A+b*B)*E-c*C)/D)+1):
                    if 100*(A*a+B*b)+C*c+D*d <= F:
                        if con <= 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D)):
                            con = 100*((c*C+d*D)/(100*a*A+100*b*B+c*C+d*D))
                            sugar = c*C+d*D
                            sugar_water = 100*a*A+100*b*B+c*C+d*D
print(sugar_water, sugar)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans=[100*a,0]
for i in range(f//(100*a)+1):
  for j in range((f-100*a*i)//(100*b)+1):
    for k in range(f//c+1):
      if i==0 and j==0:
        break
      for l in range((f-c*k)//d+1):
        if 100*a*i+100*b*j+c*k+d*l>f:
          break
        elif c*k+d*l>(a*i+b*j)*e:
          break
        else:
          if (c*k+d*l)/(100*a*i+100*b*j+c*k+d*l)>ans[1]/ans[0]:
            ans=[100*a*i+100*b*j+c*k+d*l,c*k+d*l]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans=[100*min(a,b),0]
for i in range(31):
  for j in range(31):
    if i==0 and j==0:
      break
    l1=f-(100*a*i+100*b*j)
    l2=(a*i+b*j)*e
    l=min(l1,l2)
    cc,dc=0,0
    for k in range(l//c+1):
      tc=k
      td=(l-c*tc)//d
      if l-(c*tc+d*td)<l-(c*cc+d*dc):
        cc,dc=tc,td
    wa=100*a*i+100*b*j
    sa=c*cc+d*dc
    tmp=[wa+sa,sa]
    if wa+sa>f or sa>e*(a*i+b*j):
      break
    if tmp[1]/tmp[0]>ans[1]/ans[0]:
      ans=tmp
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math



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

  # water list
  dp = [0 for i in range(F+1)]
  dp[100*A]=1
  if 100*B<=F: dp[100*B]=1
  Wn = set([100*A,100*B])
  for i in range(A,F+1):
    if dp[i]>0:
      Wn.add(i)
      if i+100*A<=F: dp[i+100*A]=1
      if i+100*B<=F: dp[i+100*B]=1

  # sugar list
  dp = [0 for i in range(F+1)]
  dp[C],dp[D]=[1,1]
  Sn = set([C,D])
  for i in range(C,F+1):
    if dp[i]>0:
      Sn.add(i)
      if i+C<=F: dp[i+C]=1
      if i+D<=F: dp[i+D]=1

  # solve
  ret = [0.0, 100*A, 0]
  for w in Wn:
    for s in Sn:
      if w+s>F or 100*s>E*w:
        continue
      elif 100*s/(w+s) > ret[0]:
        ret = [100*s/(w+s),w+s,s]
  return [ret[1],ret[2]]



if __name__ == "__main__":
  w,s = main()
  print(w,s)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
 
use_water = [] 
for i in range(0,31):
  for j in range(0,31):
    tmp = A*i + B*j
    if((tmp != 0)and(tmp <= 30)): 
      if(tmp*100 <= F):
        use_water.append(tmp)
use_water = list(set(use_water))
use_water.sort()
 
Conc = [] 
for i in range(101):
  for j in range(51):
    for k in range(len(use_water)):
      sugar = C*i + D*j
      water = use_water[k]*100
      if(sugar + water <= F):
       if(sugar <= use_water[k]*E):
        conc = sugar/(sugar + water)
        Conc.append([conc,water+sugar,sugar])
 
Conc.sort(reverse = True)
ans_water,ans_sugar = Conc[0][1],Conc[0][2]
print(ans_water,ans_sugar)

Submission status: Accepted

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

w, s = 1, -1
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        m = min(F - a - b, (a + b) * E // 100)
        if (a, b) == (0, 0):
            continue
        for c in range(0, m + 1, C):
            for d in range(0, m - c + 1, D):
                if s / w < (c + d) / (a + b):
                    w, s = a + b, c + d

print(w + s, s)

Submission status: Accepted

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

"""解説
https://www.youtube.com/watch?v=nCHz87GMdpo



"""

def solve2():
    """ 全探索O(F**2) """
    A, B, C, D, E, F = list(map(int, input().split()))

    # 水をx, 砂糖をyとする
    sugars = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            y = i*C + j*D
            if y <= F:
                # 作れる砂糖の量y[g]をメモする
                sugars.append(y)

    water = []
    for i in range(0, F+1):
        for j in range(0, F+1):
            x = 100*A*i + 100*B*j
            if x <= F:
                # 作れる水の量x[g]をメモする
                water.append(x)
    
    sugars.sort()
    water.sort()

    # 濃度
    concent = 0
    for x in water:
        for y in sugars:
            if x+y > F:
                break
            if x+y > 0 and y/(x+y) <= E/(100+E):
                if y/(x+y) >= concent:
                    concent = y/(x+y)
                    ans = "{} {}".format(x+y, y)
    print(ans)


def solve():
    """ WA """
    A, B, C, D, E, F = list(map(int, input().split()))

    # dp[i] := 砂糖水i[g]のときに作れる最大の濃度
    # 配るDP
    dp= [0]*(F+1)

    for i in range(0, F+1):
        if i+100*A <= F:
            concent = (dp[i]*i)/(i+100*A)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*A] = max(dp[i+100*A], concent)
        if i+100*B <= F:
            concent = (dp[i]*i)/(i+100*B)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+100*B] = max(dp[i+100*B], concent)
        if i+C <= F:
            concent = (dp[i]*i+C)/(i+C)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+C] = max(dp[i+C], concent)
        if i+D <= F:
            concent = (dp[i]*i+D)/(i+D)
            concent = concent if concent <= E/(100+E) else 0
            dp[i+D] = max(dp[i+D], concent)
    
    print(dp)
    return
    max_concent = max(dp)
    print(dp.index(max_concent), round(dp.index(max_concent)*max_concent))



if __name__ == "__main__":
    solve2()

Submission status: Accepted

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

def noudo(weight,sugar):
    if sugar is None:return -1000000000
    else:return(sugar*100/weight)
    
def noudosafe(w,s):
    if (noudo(w,s)<=noudo(100+E,E)):return s
    else:return None
    
def eraseNone(i):
    if i is None:return 0
    else: return i
    
dp=[None]*(F+1) #dp[x]はｘｇの砂糖水の中に最大限入っている砂糖の量
dp[0]=0
for i in range(1,F+1):#iグラムの砂糖水
    sug1,sug2,sug3,sug4=[None]*4
    if i>=100*A:
        sug1=dp[i-100*A]
        if sug1 is not None:
            sug1=noudosafe(i,sug1)
    if i>=100*B:
        sug2=dp[i-100*B]
        if sug2 is not None:
            sug2=noudosafe(i,sug2)
    if i>=C:
        sug3base=dp[i-C]
        if sug3base is not None:
            sug3=noudosafe(i,sug3base+C)
    if i>=D:
        sug4base=dp[i-D]
        if sug4base is not None:
            sug4=(noudosafe(i,sug4base+D))
            
    sug=(sug1,sug2,sug3,sug4)
    if all([k is None for k in sug]):
        continue
    else:
        dp[i]=max([eraseNone(k) for k in sug])

ansi=0
anssugar=0
maxnoudo=0
for x,s in enumerate(dp):
    if x==0:continue
    if maxnoudo<noudo(x,s):
        maxnoudo=noudo(x,s)
        ansi=x
        anssugar=s
if anssugar:print(ansi,anssugar)
else: print(100*A,0)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(65536)

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

def memoize(f):
	memo = {}
	def g(*args):
		if args not in memo:
			memo[args] = f(*args)
		return memo[args]
	return g

@memoize
def search(w, s):
	if 100*w+s > f:
		return (-1, w, s)

	if s > e * w or w == 0:
		return max(search(a+w, s), search(b+w, s))
	else:
		return max(search(w, s+c), search(w, s+d), (100*s/(100*w+s), w, s))

_,w,s=search(0, 0)
print(100*w+s, s)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
l=[]
for i in range(0,(f//(100*a))+1):
  for j in range(0,(f//(100*b))+1):
    if 100*a*i+100*b*j>f:
      pass
    else:
      l.append(100*a*i+100*b*j)
l1=[]
del l[0]
max1=0
g=0
h=0
for i in l:
  l2=[]
  m=min(f-i,(i//100)*e)
  max2=0#satounoryou
  for j in range(0,(m//c)+1):
    for k in range(0,(m//d)+1):
      if j*c+k*d<=m and j*c+k*d>max2:
        max2=j*c+k*d
  if max1<=100*max2/(i+max2):
    g=i
    h=max2
    max1=100*max2/(i+max2)
print(g+h,h)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
def solve(a,b):
    return 100*b<=E*a
def contain(a,b):
    return 0<a+b<=F
water = []
for i in range(30):
    for j in range(30):
        if 0 < 100*A*i+100*B*j <= F:
            water.append(100*A*i+100*B*j)
sugar = []
for i in range(3000):
    for j in range(3000):
        if C*i + D*j <= F:
            sugar.append(C*i + D*j)
        else:
            break
sugar.sort()
water.sort()
cand=[]
for s in sugar:
    for w in water:
        if contain(w,s):
            if solve(w,s):
                cand.append((w+s,s))
        else:
            break
cand.sort(key=lambda x:x[1]/x[0],reverse=True)
print(*cand[0])

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
ans = ["0","0"]
M = -1
for a in range(31):
    if F < a*A*100:
        break
    for b in range(31-a):
        if a == 0 and b == 0:
            continue
        W = (a*A+b*B)*100
        if F < W:
            break
        CD_max = min((E * W) // 100,F-W)
        for c in range(CD_max//C+1):
            d = max(0,(CD_max-c*C)//D)
            CD = c*C+d*D
            con = CD/(W+CD)
            if con > M:
                M = con
                ans = [str(W+CD),str(CD)]
print(" ".join(ans))

Submission status: Accepted

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

now = 0
ans_w = 0
ans_s = 0
for a in range(F//(100*A)+1):
    for b in range(F//(100*B)+1):
        for c in range(F//C+1):
            for d in range(F//D+1):
                w = A * a * 100 + B * b * 100
                s = C * c + D * d
                if s / E > w / 100 or s + w > F:
                    break
                elif w + s != 0:
                    if now < 100*s/(w+s):
                        now = 100*s/(w+s)
                        ans_w = w
                        ans_s = s

if ans_w == 0 and ans_s == 0:
    ans_w = 100 * A
print(ans_w + ans_s, ans_s)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
sugar_total = [-1, 1]
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        water = a + b
        if water == 0:
            continue
        for c in range(0, F - water + 1, C):
            for d in range(0, min(F - water - c, (water // 100) * E - c) + 1, D):
                sugar = c + d
                total = water + sugar
                if sugar / total > sugar_total[0] / sugar_total[1]:
                    sugar_total[0], sugar_total[1] = sugar, total
print(sugar_total[1], sugar_total[0])

Submission status: Accepted

Solution code:

import math

def read_input():
    a, b, c, d, e, f = map(int, input().split())
    return a, b, c, d, e, f


# 100aと100bの線形結合でf以下でとりうる値を見つける
def search_water_valiation(a, b, f):
    result = []
    for i in range(30):
        for j in range(30):
            water = 100*a*i + 100*b*j
            if water <= f:
                result.append(water)

    result = list(set(result))
    result.sort()

    return result


# c, dの線形結合でmax_sugar以下の最大値を探す
# cx + dy <= max_sugarより
# y <= - c/d x + max_sugar/d
# xの範囲は(0, max_sugar/c)
def search_most_sweet(c, d, max_sugar):
    sugars = []
    for x in range(math.floor(max_sugar/c) + 1):
        y = math.floor((-c * x + max_sugar)/d)
        sugars.append(c*x + d*y)

    sugars = list(set(sugars))
    return max(sugars)

def submit():
    a, b, c, d, e, f = read_input()

    waters = search_water_valiation(a, b, f)
    max_sugars = [min(w * e // 100, f - w) for w in waters]

    result = []
    for water, max_sugar in zip(waters, max_sugars):
        sugar = search_most_sweet(c, d, max_sugar)
        result.append((water, sugar))

    result = [r for r in result if r[0] + r[1] <= f]
    result = [(w+s, s, 100 * s / (w + s)) for (w, s) in result if (w, s) != (0, 0)]

    r = max(result, key=lambda x:x[2])
    print('{} {}'.format(r[0], r[1]))

if __name__ == '__main__':
    submit()

Submission status: Accepted

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

water = []
for a in range(F//A+1):
    for b in range(F//B+1):
        if a + b == 0 or a * A + b * B > F:
            continue
        if not((a * A + b * B) in water):
            water.append(a * A + b * B)

water.sort()

suger = []
for c in range(F//C+1):
    for d in range(F//D+1):
        if c * C + d * D > F:
            continue
        if not((c * C + d * D) in suger):
            suger.append(c * C + d * D)

suger.sort()

max_dense = 0
log = [water[0],0]
for w in water:
    for s in suger:
        dense = 100 * s / w
        if w + s > F or dense > E:
            break
        elif dense == E:
            print(" ".join(map(str,[w+s,s])))
            exit()
        elif dense > max_dense:
            max_dense = dense
            log = [w+s,s]

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

Submission status: Accepted

Solution code:
import math
A, B, C, D, E, F = map(int, input().split())
limit_r = 100 * E / (100 + E)
max_r, max_w, max_s = -1 * float('inf'), 0, 0
for a in range(math.floor(F/100/A)+1):
  for b in range(math.floor(F/100/B)+1):
    w = 100 * A * a + 100 * B * b
    if w == 0:
      continue
    if w > F:
      break
    for c in range(math.floor((F-w)/C)+1):
      for d in range(math.floor((F-w)/D)+1):
        s = C * c + D * d
        r = 100 * s / (w + s)
        if w + s > F or r > limit_r:
          break
        if r > max_r:
          max_r, max_w, max_s = r, w, s
print("{0} {1}".format(max_w+max_s, max_s))

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    A,B,C,D,E,F = (int(_) for _ in input().split())
    memo = {}
    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:
                        break
                    elif w + s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100 * s/(w+s)
                            memo[a,b,c,d] = density
    max_density = max(memo.values())
    for k,v in memo.items():
        if v==max_density:
            print((100*A)*k[0] +(100*B)*k[1]+k[2]*C + k[3]*D,k[2]*C + k[3]*D)
            break
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans1,ans2=0,0
Wat,Salt=set(),set()
for i in range(f//(100*a)+1):
  for j in range(f//(100*b)+1):
    w=a*i*100+b*j*100
    if w<=f:
      Wat.add(w)
for i in range(f//c+1):
  for j in range(f//d+1):
    s=c*i+d*j
    if s<=f:
      Salt.add(s)
Wat=list(Wat)
Salt=list(Salt)
for i in Wat:
  for j in Salt:
    if i+j<=f and j*(100+e)<=e*(i+j) and j*ans1>=ans2*(i+j):
      ans1,ans2=i+j,j
print(ans1,ans2)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans = [[0, 0]]
for i in range(0, F//100):
    if 100*A*i > F:
        break
    for j in range(0, F//100):
        if 100*A*i+100*B*j > F:
            break
        if 100*A*i + 100*B*j == 0:
            continue
        for k in range(0, F//C+1):
            for l in range(0, F//D+1):
                if 100*A*i + 100*B*j + C*k + D*l > F:
                    break
                if  (C*k + D*l)/(100*A*i + 100*B*j) > E/100:
                    break
                ans.append([(100*A*i + 100*B*j + C*k + D*l), (C*k + D*l)])
ans = sorted(ans, key=lambda x: x[1]/x[0] if x[0] != 0 else 0)
print(ans[-1][0], ans[-1][1])

Submission status: Accepted

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

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:
                    break
                if w + s > F:
                    break
                else:
                    if w / 100 * E >= s:
                        density = 100 * s / (w + s)
                        memo[a, b, c, d] = 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:
A, B, C, D, E , F = map(int, input().split())

def makeSet(a, b):
  list = []
  for i in range(int(F / a + 2)):
    for j in range(int(F / b + 2)):
      tmp = i * a + j * b
      if tmp > F:
        break
      list.append(tmp)
  return set(list)

W = makeSet(A * 100, B * 100)
S = makeSet(C, D)

def isOK(a, b):
  return b * (100 + E) <= E * (a + b) and a + b <= F

ma = F
mb = 0

def chmax(a, b):
  if b * (ma + mb) >= mb * (a + b):
    return a, b
  return ma, mb

for w in W:
  for s in S:
    if isOK(w, s):
      ma, mb = chmax(w, s)

print(ma + mb, mb)

Submission status: Accepted

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

node = 0
aa = 0
bb = 0
cc = 0
dd = 0
na = int(F/(100*A))
nb = int(F/(100*B))
nc = int(F/C)
nd = int(F/D)
for a in range(na+1):
    for b in range(nb+1):
        for c in range(nc+1):
            for d in range(nd+1):
                if 100 * A * a + 100 * B * b + C * c + D * d > F or (A * a + B * b) * E < C * c + D * d:
                    break
                else:
                    if a == b == c == d == 0:
                        continue
                    else:
                        cand = (100 * (C * c + D * d)) / (100 * (A * a + B * b) + (C * c + D * d))
                        if cand > node:
                            node = cand
                            aa = a
                            bb = b
                            cc = c
                            dd = d
if node == 0:
    print("{} {}".format(100*A, 0))
else:
    print("{} {}".format(100*(A * aa + B * bb)+(C * cc + D * dd), C * cc + D * dd))

Submission status: Accepted

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

per = 0
ans = []

for i in range(f//(100*a) + 1):
    for j in range(f//(100*b) + 1):
        w = i * a * 100 + j * b * 100
        if w > f or w == 0:
            break
        for k in range((e * w//100)//c + 1):
            for l in range((e * w//100)//d + 1):
                if e * w//100 < c * k + d * l or w + c * k + d * l > f:
                    break
                now = 100 * (c*k+d*l) / (w+c*k+d*l)
                if per < now:
                    per = now
                    ans = [w+c*k+d*l, c*k+d*l]
if ans == []:
    print(100*a, 0)
else:
    print(ans[0], ans[1])

Submission status: Accepted

Solution code:
from functools import lru_cache
import sys

sys.setrecursionlimit(1000000)

A,B,C,D,E,F = map(int,input().split())
# (water,sugar)
E2 = 100 * E / (100 + E)

@lru_cache(maxsize=10000)
def dfs(w,s):
    global A,B,C,D,E,F
    #print('dfs',w,s)
    inf = 1 << 60
    if w + s > F:
        return (-1, w, s)
    if w + s == 0:
        d = (-1, w, s)
    else:
        d = ((100 * s) / (w + s), w, s)
    #print(d)
    d1 = dfs(w + 100*A, s)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w + 100*B, s)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w, s + C)
    if d1[0] <= E2:
        d = max(d, d1)
    d1 = dfs(w, s + D)
    if d1[0] <= E2:
        d = max(d, d1)

    return d

ans = dfs(0,0)
print(ans[1]+ans[2],ans[2])

Submission status: Accepted

Solution code:
EPS = 1E-8
def solve(a, b, c, d, e, f):
    threshold = e / (100 + e) + EPS
    best = -1
    for x in range(0, f+1, 100*a):
        for y in range(x, f+1, 100*b):
            if y == 0:
                continue
            for z in range(y, f+1, c):
                for w in range(z, f+1, d):
                    p = w - y
                    cur = p / w
                    if best < cur <= threshold:
                        best = cur
                        solution = (w, p)
    return "%d %d" % solution

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

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
aa=-1
ans=[0,0]
for i in range(0,f+1,a*100):
  for j in range(0,f+1-i,b*100):
    for k in range(0,int(e*(i+j)/100)+1,c):
      for l in range(0,int(e*(i+j)/100)+1-k,d):
        if i+j+k+l>f:
          continue
        if i+j>0 and aa<(k+l)/(i+j+k+l):
          aa=(k+l)/(i+j+k+l)
          ans=[i+j+k+l,k+l]
print(ans[0],ans[1])

Submission status: Accepted

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

con = -1
ans_w, ans_s = 0, 0
for i in range(F//(100*A) + 1):
    water = i*100*A
    for j in range((F-water)//(100*B) + 1):
        if i == 0 and j == 0:
            continue
        water += j*100*B
        for k in range((F-water)//C + 1):
            flg = 0
            sugar = k*C
            water += sugar
            if sugar > (A*i+B*j)*E:
                water = i*100*A
                break
            for l in range((F-water)//D + 1):
                sugar += l*D
                water += l*D
                if sugar > (A*i+B*j)*E:
                    water -= sugar
                    flg = 1
                    break
                tmp = 100*sugar/water
                if tmp > con:
                    con = tmp
                    ans_w = water
                    ans_s = sugar
                water -= l*D
                sugar -= l*D
            if flg == 0:
                water -= k*C

print(ans_w, ans_s)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc074/tasks/arc083_a

import itertools
from collections import Counter
import bisect

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

    ans_nod = -1
    ans_sugar = 0
    ans_water = 0
    for a in range(31):
        for b in range(31):
            water = a * A * 100 + b * B * 100
            if water == 0:
                continue
            if water > F:
                continue
            max_sugar = E * (a * A + b * B)
            for i in range(3000):
                for j in range(3000):
                    sugar = i * C + j * D
                    if sugar > max_sugar:  # 解けないならダメ
                        break
                    if sugar + water > F:  # F超えるならダメ
                        break
                    nod = 100 * sugar / (water + sugar)
                    if nod > ans_nod:
                        ans_nod = nod
                        ans_sugar = sugar
                        ans_water = water
    print("{} {}".format(ans_water + ans_sugar, ans_sugar))


if __name__ == '__main__':
    main()