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:
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]  # グループ番号
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)


A, B, C, D, E, F = map(int, input().split())
ma = F // (100 * A)
mb = F // (100 * B)
mc = F // C
md = F // D
a = 0
s = 0
d = 0
sw = 0
ss = 0
sd = 0
for i in range(ma + 1):
    if A * 100 * i > F:
        break
    for j in range(mb + 1):
        if A * 100 * i + B * 100 * j > F:
            break
        for k in range(mc + 1):
            if A * 100 * i + B * 100 * j + C * k > F:
                break
            for l in range(md + 1):
                if A * 100 * i + B * 100 * j + C * k + D * l > F:
                    break
                if i + j == 0:
                    break
                a = A * 100 * i + B * 100 * j + C * k + D * l
                s = C * k + D * l
                d = s / (A * i + B * j)
                # print(i, j, a, F, d, E)
                if a <= F and sd <= d <= E:
                    sd = d
                    sw = a
                    ss = s
                    # print(a, s, d, i, j)
print(sw, ss)

Submission status: Accepted

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

use_water = [] #使える水の量を100で割った値
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()
#砂糖の入れ方は多く見積もってもせいぜい
#0,C,2C,...,100C
#D,C+D,...,100C+D
#...
#50D,C+50D,...,100C+50D
#-> 100*50 = 5000通り

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):
        #濃度
        #print('sugar:',sugar,'water:',water,'max_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:
# encoding:utf-8
import copy
import numpy as np
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import math

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

water = []
for ai in range(int(F/(A*100))+1):
    for bi in range(int(F/(B*100))+1):
        if (ai*A+bi*B)*100>F:pass
        else:
            water.append((ai*A+bi*B)*100)

suger = []
for ci in range(int(F/C)+1):
    for di in range(int(F/D)+1):
        if ci*C+di*D > F:
            pass
        else:suger.append(ci*C+di*D)

water = list(set(water))
suger = list(set(suger))
water.remove(0)
pure = 0
ans_s,ans_w = 0,A*100
for wi in range(len(water)):
    for si in range(len(suger)):
        if water[wi]+suger[si]>F:pass
        else:
            if pure<suger[si]/(water[wi]+suger[si])<=(E/(100+E)):
                ans_s = suger[si]
                ans_w = water[wi]
                pure = suger[si]/(water[wi]+suger[si])

print(ans_s+ans_w,end="")
print(" ",end="")
print(ans_s)

Submission status: Accepted

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

for i in range(0,31):
    for j in range(0,31):
        water = 100*a*i+100*b*j
        if water > f:
            break
        Water.append(water)
for i in range(f//min(c,d)+1):
    for j in range(f//min(c,d)+1):
        sugar = c*i + d*j
        if sugar > f:
            break 
        Sugar.append(sugar)
Sugar=list(set(Sugar))
Water = list(set(Water))
        

def Noudo(x,y):
    if(x>0 and y>0):
        return 100*y/(x+y)
    else:
        return 0
Max = 0
tmp_w,tmp_s = 100*a,0
for i in Water:
    for j in Sugar:
        if (i/100*e >= j) and (i+j <= f):
            tmp = Noudo(i,j)
            if Max < tmp:
                Max = tmp
                tmp_w = i+j
                tmp_s = j
print(tmp_w,tmp_s)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split());ans,ma=[0]*2,0
for i in range(f//100+1):
  if i%b==0 or i%a==0:
    w=i*100
    x=min(f-w,i*e)
    s=0
    for j in range(x//c+1):
      ss=j*c
      s=max(s,ss+((x-ss)//d)*d)
    if w!=0:
      if ma<=(100*s)/(w+s):ans=[w,s];ma=(100*s)/(w+s)
print(ans[0]+ans[1],ans[1])

Submission status: Accepted

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

water = set()
for i in range(31):
    for j in range(31):
        w = i*a + j*b 
        if w <= f // 100:
            water.add(w)
water = sorted(water)
sugar = set()
for i in range(1501):
    j = 0
    while i*c + j*d <= 1500:
        sugar.add(i*c + j*d)
        j += 1
sugar = sorted(sugar)
ans = []
for w in water:
    sid = bisect.bisect_right(sugar, w*e) - 1
    while sugar[sid] + w*100 > f and sid > 0:
        sid -= 1
    if w != 0:
        total = w*100 + sugar[sid]
        ans.append([sugar[sid]/total, total, sugar[sid]])
ans.sort(key=lambda x:x[0])
print(ans[-1][1], ans[-1][2])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().rstrip().split())
water = []
for i in range(A+1):
    for j in range(B+1):
        tmp = A*i*100 + B*j*100
        if tmp < F: 
            water.append(tmp)
        else:
            break
water.sort(reverse=True)
water.pop()
maximum = [water[0], 0]
concentration = 0
for i in water:
    multi = i//100
    suger_limit = E*multi if E*multi + i <= F else F - i
    for j in range(100):
        for k in range(100):
            suger = C*j + D*k
            if suger > suger_limit:
                break
            if concentration < 100*suger / (i + suger):
                concentration = 100*suger / (i + suger)
                maximum = [i+suger, suger]
print(*maximum, sep=" ")

Submission status: Accepted

Solution code:
import itertools

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

a *= 100
b *= 100
waters = set()
for i in range(0, f // a + 1):
    for j in range(0, (f - a * i) // b + 1):
        waters.add(a * i + b * j)

sugers = set()
g = f // 100 * e
for i in range(0, g // c + 1):
    for j in range(0, (g - c * i) // d + 1):
        sugers.add(c * i + d * j)

answers = set()
for water, suger in itertools.product(waters, sugers):
    if water > 0 and water + suger <= f and suger <= water // 100 * e:
        answers.add((suger + water, suger))

weight, suger = max(answers, key=lambda answer: answer[1] / answer[0])
print(weight, suger)

Submission status: Accepted

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

W = set()
for a in range(F // (100 * A) + 1):
    for b in range(F // (100 * B) + 1):
        if a == b == 0: continue
        w = 100 * (A * a + B * b)
        if w <= F:
            W.add(w)

S = set()
for c in range(F // C + 1):
    for d in range(F // D + 1):
        s = C * c + D * d
        if s <= F:
            S.add(s)

max_density = -1
max_ws = 0
max_s = 0
for w in W:
    for s in S:
        if w + s > F or E * w / 100 < s: continue
        density = s / (w + s)
        if density > max_density:
            max_density = density
            max_ws = w + s
            max_s = s

print(max_ws, max_s)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in reversed(sorted(list(W))):
  for sgr in reversed(sorted(list(S))):
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
      if anssgr*(100+E)==E*(answtr+anssgr):
        print("{} {}".format(answtr+anssgr, anssgr))
        exit()
print("{} {}".format(answtr+anssgr, anssgr))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in W:
  for sgr in S:
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
      if anssgr*(100+E)==E*(answtr+anssgr):
        print("{} {}".format(answtr+anssgr, anssgr))
        exit()
print("{} {}".format(answtr+anssgr, anssgr))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in W:
  for sgr in S:
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
print("{} {}".format(answtr+anssgr, anssgr))

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
waters = set()
iM = F//(100*A) + (not not F%(100*A))
jM = F//(100*B) + (not not F%(100*B))
for i in range(iM):
    for j in range(jM):
        if i*A*100+j*B*100>F:
            continue
        else:
            waters.add((i*A*100+j*B*100,(i*A+j*B)*E))

waters = list(waters)
waters.sort()

maxW,maxS = A*100,0
sugars = [False]*3001
sugars[0] = True

for i in range(3001):
    if sugars[i]:
        if i+C <3001:
            sugars[i+C]=True
        if i+D <3001:
            sugars[i+D]=True 
#print(waters)
for water,sugarM in waters:
    for i in range(sugarM,-1,-1):
        if i+water>F:
            continue
        if sugars[i]:
            maxSugar = i
            break
#    print(water,maxSugar) 
    if (maxSugar+water)*maxS<maxSugar*(maxW+maxS):
        maxW = water
        maxS = maxSugar
print(maxW+maxS,maxS)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
ans = []
for ai in range(31):
    bb = (f - (ai * a * 100)) // b
    for bi in range(bb + 1):
        if ai == bi == 0:
            continue
        cc = (f - (ai * a * 100 + bi * b * 100)) // c
        for ci in range(cc + 1):
            dd = (f - (ai * a * 100 + bi * b * 100 + ci * c)) // d
            for di in range(dd + 1):
                if 100 * a * ai + 100 * b * bi + c * ci + d * di <= f:
                    if (c * ci + d * di)/(100 * a * ai + 100 * b * bi) <= e/100:
                        ans.append([(c * ci + d * di)/(100 * a * ai + 100 * b * bi + c * ci + d * di), 100 * a * ai + 100 * b * bi + c * ci + d * di, c * ci + d * di])
ans.sort(reverse=True)
print(ans[0][1], ans[0][2])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
beaker = {'water':0, 'sugar':0, 'percent':0}
maxpercent=e/(100+e)
maxtimes = f // (100 + e)
maxc = e*maxtimes//c
percent = 0
for i in range(maxc + 1):
    for j in range((e*maxtimes-i*c)//d + 1):
        sugar = i*c + j*d
        minwater = sugar/maxpercent - sugar
        maxa = int((minwater + 100*a)//(100*a))
        maxb = int((minwater + 100*b)//(100*b))
        for atimes in range(maxa + 1):
            for btimes in range(maxb + 1):
                if 100 * (atimes * a + btimes * b)< minwater:
                    continue
                water = 100 * (atimes * a + btimes * b)
                if water + sugar == 0 or water + sugar > f:
                    continue
                percent = 100 * sugar/(water + sugar)
                if beaker['percent'] <= percent:
                    beaker['water']=water
                    beaker['sugar']=sugar
                    beaker['percent']=percent
print(str(beaker['water']+beaker['sugar']) + ' ' + str(beaker['sugar']))

Submission status: Accepted

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

from fractions import gcd

highest_concentration=-1

for a in range(F//(100*A) +1):
  for b in range((F-100*A*a)//(100*B) +1):
    water = 100*A*a + 100*B*b
    if not water:
      continue
      
    max_sugar = min(E*(A*a+B*b), F-water)
    
    for c in range(min(D,(max_sugar//C)+1)):
      d = (max_sugar -c*C)//D
      sugar = c*C + d*D
      if sugar/(water+sugar) > highest_concentration:
        highest_concentration = sugar/(water+sugar)
        #print(a,b,c,d, 100*a*A+100*b*B, sugar)
        #print(water,water+sugar, sugar)
        answer = (water+sugar, sugar)
        
print(*answer)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
water=[]
salt=[]
for i in range(30):
  for j in range(30):
    x=a*100*i+b*100*j
    if x<=f:
      water.append(x)
for i in range(1501):
  for j in range(1501):
    x=c*i+d*j
    if x<=f:
      salt.append(x)
water=list(set(water))
salt=list(set(salt))
stack=0
ans_sol=min(a*100,b*100)
ans_sal=0
for i in water:
  for j in salt:
    if 1<=i+j<=f and j*100<=i*e:
      if j/(i+j)>stack:
        stack=j/(i+j)
        ans_sol=i+j
        ans_sal=j
print(ans_sol,ans_sal)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
dp=[-1]*(f+1)
dp[0]=0
flag=True
for i in range(1,f+1):
  for j in [a*100,b*100]:
    if i-j>=0 and dp[i-j]!=-1:
      dp[i]=max(0,dp[i])
  for j in [c,d]:
    if i-j>=0 and dp[i-j]!=-1:
      if 100*(dp[i-j]+j)<=e*(i-(dp[i-j]+j)):
        dp[i]=max(dp[i],dp[i-j]+j)
      else:
        for k in [a*100,b*100]:
          if i-k-j>=0 and dp[i-k-j]!=-1:
            if 100*(dp[i-k-j]+j)<=e*(i-(dp[i-k-j]+j)):
              dp[i]=max(dp[i],dp[i-k-j]+j)
stack=0
index=min(a*100,b*100)
for i in range(index+1,f+1):
  if dp[i]>0:
    if stack<(dp[i]*100)/i:
      stack=(dp[i]*100)/i
      index=i
print(index,dp[index])

Submission status: Accepted

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

Submission status: Accepted

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

W = set()
for i in range(0,F+1,100*A):
    for j in range(0,F+1-i,100*B):
        W.add(i+j)
        
S = set()
for i in range(0,F+1,C):
    for j in range(0,F+1-i,D):
        S.add(i+j)

rate = 0
for w in W:
    for s in S:
        if 0 < w+s <= F and s/(w+s) <= E/(E+100):
            if s/(w+s) >= rate:
                rate= s/(w+s)
                res1,res2 = w+s,s
                
print(res1,res2)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
A*=100
B*=100
ans=(A,0)
Max=0
for a in range(1+F//A):
    F_a=F-a*A
    water_a=a*A
    for b in range(1+F_a//B):
        F_b=F_a-b*B
        water_b=water_a+b*B
        for c in range(1+F_b//C):
            suger_c=c*C
            if suger_c>E*water_b/100:break
            F_c=F_b-c*C
            d=min(F_c//D,(E*water_b//100-suger_c)//D)
            suger_d=suger_c+d*D
            if water_b+suger_d==0:continue
            if suger_d/(water_b+suger_d)>Max:
                Max=suger_d/(water_b+suger_d)
                ans=(water_b+suger_d,suger_d)
print(str(int(ans[0]))+' '+str(int(ans[1])))

Submission status: Accepted

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


for i in range(1, F//(100*A)+1):
    for j in range(F//(100*A)+1):
        if 100*A*i+100*B*j>F:
            break
        for k in range(E*(A*i+B*j)+1):
            if 100*A*i+100*B*j+C*k>F or C*k>E*(A*i+B*j):
                    break
            for l in range(E*(A*i+B*j)+1):
                if 100*A*i+100*B*j+C*k+D*l>F or C*k+D*l>E*(A*i+B*j):
                    break
                tmp = 100*(C*k+D*l)/(100*A*i+100*B*j+C*k+D*l)
                if tmp > conc:
                    conc = tmp
                    answater = 100*A*i+100*B*j+C*k+D*l
                    anssugar = C*k+D*l

print(answater, anssugar)

Submission status: Accepted

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

max_sw = 100 * a
max_s = 0
x = f // (a * 100)
y = f // (b * 100)
for i in range(x + 1):
    for j in range(y + 1):
        if i == 0 and j == 0:
            continue
        water = i * a * 100 + j * b * 100
        if water <= f:
            z = e * water // 100 // c
            w = e * water // 100 // d
            for k in range(z + 1):
                for l in range(w + 1):
                    sugar = k * c + l * d
                    if sugar + water <= f and e * water // 100 >= sugar \
                            and water + sugar > 0:
                        density = sugar / (sugar + water)
                        if density >= max_s / max_sw:
                            max_s = int(sugar)
                            max_sw = int(sugar + water)


print("{} {}".format(max_sw, max_s))

Submission status: Accepted

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

water = 0
sugar = 0
rate = 0

for x in range(31):
    for y in range(31):
        if x + y == 0:
            continue
        for z in range(101):
            for w in range(101):
                now_water = 100*a*x + 100*b*y + c*z + d*w
                if now_water > f:
                    break
                now_sugar = c*z + d*w
                if now_water*e >= now_sugar*(100 + e):
                    now_rate = now_sugar/now_water
                    if rate <= now_rate:
                        rate = now_rate
                        water = now_water
                        sugar = now_sugar


print(water,sugar)

Submission status: Accepted

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

ans = 0
ansa = 0
ansb = 0


for a in range(0,(F//(100*A))+1):
    #水をa*A使う。
    for b in range(0,((F-100*a*A)//(100*B))+1):
        #水をb*B使う。
        #print(a,b)
        for pa in range((E*(a*A+b*B)//C) + 1):
            #print("お伝えするよ")
            limsug = F-100*(a*A+b*B)-pa*C
            if limsug>0:
                for ja in range((limsug//D)+1):

                    if a+b+pa+ja != 0:
                        nodo = 100*(pa*C+ja*D)/(100*(a*A+b*B)+pa*C+ja*D)
                        #print(a*A*100,b*B*100,pa*C,ja*D,nodo)

                        #print(a*A*100,b*B*100,pa*C,ja*D,nodo)
                        if nodo <= E and ans <= nodo and E*(a*A+b*B)>=pa*C+ja*D:
                            ans = nodo
                            ansa = 100*(a*A+b*B)+pa*C+ja*D
                            ansb = pa*C+ja*D


print(ansa,ansb)

Submission status: Accepted

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

ans = {}


def main():
    MAX_A = F // (100 * A)

    for i in range(MAX_A + 1):
        MAX_B = (F - i * 100 * A) // (100 * B)

        for j in range(MAX_B + 1):
            if i == 0 and j == 0:
                continue

            a = i * A + j * B

            SAT = a * E

            CD = F - a * 100

            SAT_FLG = True

            if CD < SAT:
                SAT_FLG = False

            CD = min(SAT, CD)

            MAX_C = CD // C

            for k in range(MAX_C + 1):
                l = (CD - k * C) // D

                b = k * C + l * D

                if SAT == b:
                    print(a * 100 + b, b)
                    return

                LACK = SAT - b
                if not LACK in ans:
                    # Create New
                    ans[LACK] = (a * 100 + b, b, SAT_FLG)
                elif not ans[LACK][-1]:
                    # SAT_FLG False
                    # Overwrite
                    ans[LACK] = (a * 100 + b, b, SAT_FLG)

    print(" ".join([str(i) for i in ans[min(ans.keys())][:-1]]))
    return


main()

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    A = list(map(int, input().split()))

    wat1 = A[0] * 100
    wat2 = A[1] * 100
    sug1 = A[2]
    sug2 = A[3]
    max_conc = A[4]
    max_volume = A[5]
    max_suger = max_conc * max_volume // 100

    W = set()
    for i in range(31):
        for j in range(31):
            w = wat1 * i + wat2 * j
            if w <= max_volume:
                W.add(w)

    S = set()
    for i in range(max_suger):
        for j in range(max_suger):
            s = sug1 * i + sug2 * j
            if s <= max_volume:
                S.add(s)

    vol = 0
    suger = 0
    conc = 0
    for w in W:
        if w == 0:
            continue
        for s in S:
            cur_conc = s / (w / 100)
            if cur_conc > max_conc:
                continue

            cur_conc = 100 * s / (w + s)
            if cur_conc >= conc and w+s <= max_volume:
                conc = cur_conc
                vol = w + s
                suger = s

    print(vol, suger)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
mizu = 0
satou = 0
noudo = 0
for i in range(0,F//(100*A)+1):
  for j in range(0,F//(100*B)+1):
    curmizu = (A*i+B*j)*100
    for k in range(0,(curmizu*E//(100*C))+1):
      for l in range(0,(curmizu*E//(100*D))+1):
        cursatou = k*C+l*D
        if curmizu+cursatou <= F:
          if cursatou <= curmizu*E/100:
            if curmizu+cursatou != 0:
              if 100*(cursatou)/(curmizu+cursatou) >= noudo:
                mizu = curmizu
                satou = cursatou
                noudo = 100*(cursatou)/(curmizu+cursatou)
print(mizu+satou,satou)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
ans = []
def my_max(x,y):
    if x[0] < y[0]:
        return y
    else:
        return x
maxi = [0,0,0]
for a in range(F // (A*100) + 1):
    for b in range(F // (B*100) + 1):
        water =  100*a*A + 100*b*B 
        if water <= F:
            for c in range(E*water//100//C+1):
                for d in range(E*water//100//D+1):
                    suger = C*c + D*d
                    if suger+water <= F and E*water//100 >= suger \
                    and water + suger > 0:
                        t = (suger/(suger+water),suger+water,suger)
                        maxi = my_max(t,maxi)
ans.sort()
print(maxi[1],maxi[2])

Submission status: Accepted

Solution code:
def sugar_water(A: int, B: int, C: int, D: int, E: int, F: int)->tuple:
    max_dens = 0
    min_a, min_b, min_c, min_d = 0, 0, 0, 0
    for a in range(F//(100*A) + 1):
        for b in range((F-100*A*a)//(100*B) + 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):
                    if F < 100*A*a + 100*B*b + c + d:
                        continue
                    if E * (100*a*A + 100*b*B) < (c*C + d*D) * 100:
                        continue
                    if a == 0 and b == 0 and c == 0 and d == 0:
                        continue

                    dens = (c*C + d*D) / (100*a*A + 100*b*B + c*C + d*D)

                    if max_dens < dens:
                        min_a, min_b, min_c, min_d = a, b, c, d
                        max_dens = dens
    if min_a == 0 and min_b == 0 and min_c == 0 and min_d == 0:
        min_a = 1
    return 100*A*min_a + 100*B*min_b + C*min_c + D*min_d, C*min_c + D*min_d


if __name__ == "__main__":
    A, B, C, D, E, F = map(int, input().split())
    w, s = sugar_water(A, B, C, D, E, F)
    print(w, s)

Submission status: Accepted

Solution code:

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

    x_list = []
    for i in range(F+1):
        for j in range(F+1):
            x = 100*A*i + 100*B*j
            if x <= F:
                x_list.append(x)

    y_list = []
    for i in range(F+1):
        for j in range(F+1):
            y = i*C + j*D
            if y <= F:
                y_list.append(y)

    res = 0
    res_x = 0
    res_y = 0

    x_list = list(set(x_list))
    y_list = list(set(y_list))

    for x in x_list:
        for y in y_list:
            if x + y > F:
                continue

            if y == 0:
                tmp = 0
            else:
                tmp = y/(x+y)

            if tmp > E/(100+E):
                continue

            if res <= tmp:
                res = tmp
                res_x = x
                res_y = y


    print(res_x+res_y,res_y)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
water = []
for i in range(int(f/100)+1):
    for j in range(int(f/100)+1):
        if 0 < a*i*100 + b*j*100 <= f:
            water.append(a*i*100 + b*j*100)
water.sort()
sugar = []
for i in range(int(f/c)+1):
    for j in range(int(f/d)+1):
        if c*i+(c*i)*e/100 + d*j+(d*j)*e/100 <= f:
            sugar.append(c*i + d*j)
sugar.sort(reverse=True)
check = -1.0
for w in list(set(water)):
    for s in list(set(sugar)):
        if w+s <= f and s <= w*e/100:
            if check < 100*s/(w+s):
                check = 100*s/(w+s)
                ans1, ans2 = w+s, s
print(ans1, ans2)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
waters = set()
sugars = set()
for i in range(F//(A*100)+1):
    for j in range(F//(B*100)+1):
        if i!=0 or j!=0:
            if A*i*100 +B*j*100 <= F:
                waters.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:
            sugars.add(C*i+D*j)

max_ratio = 0
for water in waters:
    for sugar in sugars:
        ratio =  sugar/(water+sugar)
        if water+sugar<=F and sugar<=E*(water//100):
            if ratio >= max_ratio:
                ans = (water+sugar, sugar)
                max_ratio = ratio
print(*ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/23
Solved on 2019/3/
@author: shinjisu
"""


# ABC 074 C - Sugar Water

def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    global E, F
    db = Debug()
    db.off()
    A, B, C, D, E, F = getIntList()
    db.dmp((A, B, C, D, E, F), 'A, B, C, D, E, F')
    a = F // (100 * A)
    b = F // (100 * B)
    c = F // C
    d = F // D
    db.dmp((a, b, c, d), 'a, b, c, d')
    maxConc, maxWater, maxSugar = -1.0, 0, 0
    for i in range(a+1):
        for j in range(b+1):
            water = A*i + B*j
            if water == 0:
                continue
            if water*100 >= F:  # overflow
                break
            for n in range(c+1):
                for m in range(d+1):
                    sugar = C*n + D*m
                    conc = sugar / (sugar+water*100) * 100
                    #db.dmp((maxconc, water, sugar, conc),'maxconc, water, sugar, conc')
                    if sugar/water > E:  # not all melted
                        #db.dmp('not all melted')
                        break
                    if water*100+sugar > F:  # overflow
                        #db.dmp('overflow')
                        break
                    if conc > maxConc:
                        #db.dmp('MAX UPDATED')
                        maxConc, maxWater, maxSugar = conc, water, sugar

    db.dmp((maxConc, maxWater, maxSugar),'max conc, water, sugar')
    return maxWater*100+maxSugar, maxSugar


ans = prob()
for elm in ans:
    print(elm, end=' ')