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

weight = 100 * A
suger = 0
den = 0
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        w = a + b
        if w == 0:
            continue
        S = E * w // 100
        for c in range(0, S + 1, C):
            for d in range(0, S - c + 1, D):
                s = c + d
                if w > 0 and w + s <= F and w * E >= s * 100:
                    tden = s / w
                    if den < tden:
                        weight = s + w
                        suger = s
                        den = tden

print(weight, suger)

Submission status: Accepted

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

ans=0
ans_s=0
ans_all=100*a
wlist=[]
slist=[]
for i in range(f//(100*a)+1):
    for j in range((f-i*100*a)//(100*b)+1):
        wlist.append(100*a*i+100*b*j)
for i in range((f*e//100)//c+1):
    for j in range((f*e//100)//d+1):
        slist.append(c*i+d*j)
wlist=set(wlist)
slist=set(slist)
for w in wlist:
    for s in slist:
        if w+s==0:break
        if s*100/(w+s)>ans and w*e/100>=s and w+s<=f:
            ans=s*100/(w+s)
            ans_s=s
            ans_all=w+s
print(ans_all,ans_s)

Submission status: Accepted

Solution code:
#074_C
from bisect import bisect_left, bisect_right
a, b, c, d, e, f = map(int, input().split())
water = set()
sugar = set()
for i in range(30):
    for j in range(30):
        if 0 < (a * i + b * j) * 100 <= f:
            water.add((a * i + b * j) * 100)
for i in range(f//c + 1):
    for j in range(f//d + 1):
        if 0 < (c * i + d * j) <= f:
            sugar.add(c * i + d * j)
water = sorted(list(water))
sugar = sorted(list(sugar))
ans = [100 * a, 0]
for w in water:
    x = min(w * e // 100, f - w)
    if bisect_right(sugar, x) == 0:
        continue
    s = sugar[bisect_right(sugar, x) - 1]
    if ans[1] * (s + w) < s * ans[0]:
        ans = [s+w, s]
print(*ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
dp=[0]*(3000+1)
for i in range(f//c+1):
    for j in range(f//d+1):
        if c*i+d*j<=3000:
            dp[c*i+d*j]=c*i+d*j
for i in range(1,3001):
    dp[i]=max(dp[i],dp[i-1])
ans_den=min(100*a,100*b)
ans_num=0
ans=0
for i in range(f//a+1):
    for j in range(f//b+1):
        #so we have put 100*a*i +100*b*j amount of water 
        w=100*i*a+100*j*b
        if w>f or w==0:
            continue
        rem=f-w
        sugar_max=min(e*(i*a+j*b),rem)
        val=dp[sugar_max]
        if val/(w+val)>ans:
            ans=val/(w+val)
            ans_num=val
            ans_den=w+val
print(ans_den,ans_num)

Submission status: Accepted

Solution code:
def calcCons(nA, nB, nC, nD):
    W = (nA * a + nB * b) * 100
    S = nC * c + nD * d
    if W + S == 0:
        return -1
    return S / (W + S)


a, b, c, d, e, f = map(int, input().split())
nA, nB, nC, nD, W, S, M = 0, 0, 0, 0, 0, 0, 0
while nA * a * 100 + nB * b * 100 + nC * c + nD * d <= f:
    while nA * a * 100 + nB * b * 100 + nC * c + nD * d <= f:
        while nA * a * 100 + nB * b * 100 + nC * c + nD * d <= f:
            while nA * a * 100 + nB * b * 100 + nC * c + nD * d <= f:
                cons = calcCons(nA, nB, nC, nD)
                if cons > M and cons <= e / (100 + e):
                    M = cons
                    W, S = nA * a * 100 + nB * b * 100, nC * c + nD * d
                nD += 1
            nD = 0
            nC += 1
        nC = 0
        nB += 1
    nB = 0
    nA += 1

if M == 0:
    W = a * 100
print(W + S, S)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
a *= 100
b *= 100
den = -1
sugar = 0
water = 0
for i in range(0,f+1,a):
    for j in range(0,f-i+1,b):
        for k in range(0,f-i-j+1,c):
            for l in range(0,f-i-j-k+1,d):
                w = i+j
                s = k+l
                if w == 0: break
                if s/w > e/100: continue
                x = s/(w+s)
                if x > den:
                    den = x
                    water = w
                    sugar = s
        else:
            continue
        break
print(sugar+water,sugar)

Submission status: Accepted

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

water = [False]*(f+1)
suger = [False]*(f+1)

for i in range(0, f+1, a*100):
  water[i] = True
for i in range(f+1):
  if (i == 0 or water[i]) and i+b*100 <= f:
    water[i+b*100] = True
  
for i in range(0, f+1, c):
  suger[i] = True
for i in range(f+1):
  if (i == 0 or suger[i]) and i+d <= f:
    suger[i+d] = True

ans_w, ans_s = a*100, 0
for i in range(f+1):
  if water[i] == False:
    continue
  for j in range(f, -1, -1):
    if suger[j] == False or j*(100+e) > (j+i)*e or j+i > f:
      continue
    if j*(ans_w+ans_s) > (j+i)*ans_s:
      ans_w, ans_s = i, j
    break
print(ans_w+ans_s, ans_s)

Submission status: Accepted

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

dp = [[0, 0] for _ in range(f+1)]
dp[a][0] = a
if b <= f:
    dp[b][0] = b
memo = {(a, 0):0}
for i in range(1, f):
    w, s = dp[i]
    if w:
        for ab in (a, b):
            if i+ab <= f:
                dp[i+ab][0] = w + ab
                dp[i+ab][1] = s
        for cd in (c, d):
            if i+cd <= f and s + cd <= w * e // 100:
                x = dp[i+cd][0] = w
                y = dp[i+cd][1] = s + cd
                memo[(x+y, y)] = y/(x+y)
_, z, y = max([(val, z, y) for (z, y), val in memo.items()])
print(z, y)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
a, b = 100*a, 100*b
 
dp = [[0, 0] for _ in range(f+1)]
memo = {(a, 0):0}
dp[a][0] = a
if b <= f:
    dp[b][0] = b
for i in range(1, f):
    if dp[i][0]:
        if i+a <= f:
            dp[i+a][0] = dp[i][0] + a
            dp[i+a][1] = dp[i][1]
        if i+b <= f:
            dp[i+b][0] = dp[i][0] + b
            dp[i+b][1] = dp[i][1]
        if i+c <= f and dp[i][1] + c <= dp[i][0] * e // 100:
            x = dp[i+c][0] = dp[i][0]
            y = dp[i+c][1] = dp[i][1] + c
            memo[(x+y, y)] = y/(x+y)
        if i+d <= f and dp[i][1] + d <= dp[i][0] * e // 100:
            x = dp[i+d][0] = dp[i][0]
            y = dp[i+d][1] = dp[i][1] + d
            memo[(x+y, y)] = y/(x+y)
_, z, y = max([(val, z, y) for (z, y), val in memo.items()])
print(z, y)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
wDP=[False]*((F//100)+1)
wDP[0]=True
water=[]
for i in range(1,(F//100)+1):
    if(i>=B and wDP[i-B]):
        wDP[i]=True
    elif(i>=A and wDP[i-A]):
        wDP[i]=True
for i in range((F//100)+1):
    if(wDP[i] and i!=0):
        water.append(i*100)
water=list(set(water))
ans=[water[0],0]
mconc=0
for x in water:
    up=min(x*E//100,F-x)
    sDP=[0]*(up+1)
    for i in range(1,up+1):
        if(i>=D):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C,sDP[i-D]+D)
        elif(i>=C):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C)
        else:
            sDP[i]=sDP[i-1]
    conc=100*sDP[-1]/(x+sDP[-1])
    if(conc>=mconc):
        mconc=conc;ans[0]=x+sDP[-1];ans[1]=sDP[-1]
print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
wDP=[False]*(F+1)
wDP[0]=True
water=[]
for i in range(1,(F//100)+1):
    if(i>=B and wDP[i-B]):
        wDP[i]=True
    elif(i>=A and wDP[i-A]):
        wDP[i]=True
for i in range(F+1):
    if(wDP[i] and i!=0):
        water.append(i*100)
A,B=A*100,B*100
water=list(set(water))
ans=[water[0],0]
mconc=0
for x in water:
    up=min(x*E//100,F-x)
    sDP=[0]*(up+1)
    for i in range(1,up+1):
        if(i>=D):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C,sDP[i-D]+D)
        elif(i>=C):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C)
        else:
            sDP[i]=sDP[i-1]
    conc=100*sDP[-1]/(x+sDP[-1])
    if(conc>=mconc):
        mconc=conc;ans[0]=x+sDP[-1];ans[1]=sDP[-1]
print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
wDP=[False]*(F+1)
wDP[0]=True
water=[]
for i in range(1,int(F/100)+1):
    if(i>=B and wDP[i-B]):
        wDP[i]=True
    elif(i>=A and wDP[i-A]):
        wDP[i]=True
for i in range(F+1):
    if(wDP[i] and i!=0):
        water.append(i*100)
A,B=A*100,B*100
water=list(set(water))
ans=[water[0],0]
mconc=0
for x in water:
    up=min(x*E//100,F-x)
    sDP=[0]*(up+1)
    for i in range(1,up+1):
        if(i>=D):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C,sDP[i-D]+D)
        elif(i>=C):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C)
        else:
            sDP[i]=sDP[i-1]
    conc=100*sDP[-1]/(x+sDP[-1])
    if(conc>=mconc):
        mconc=conc;ans[0]=x+sDP[-1];ans[1]=sDP[-1]
print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
A,B=A*100,B*100
water=[]
for i in range(F//A+1):
    for j in range(F//B+1):
        if A*i+B*j<=F and not(i==0 and j==0):
            water.append((A*i+B*j))
water=list(set(water))
ans=[water[0],0]
mconc=0
for x in water:
    up=min(x*E//100,F-x)
    sDP=[0]*(up+1)
    for i in range(1,up+1):
        if(i>=D):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C,sDP[i-D]+D)
        elif(i>=C):
            sDP[i]=max(sDP[i-1],sDP[i-C]+C)
        else:
            sDP[i]=sDP[i-1]
    conc=100*sDP[-1]/(x+sDP[-1])
    if(conc>=mconc):
        mconc=conc;ans[0]=x+sDP[-1];ans[1]=sDP[-1]
print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
A,B=A*100,B*100
water=[]
for i in range(F//A+1):
    for j in range(F//B+1):
        if A*i+B*j<=F and not(i==0 and j==0):
            water.append((A*i+B*j))
water=list(set(water))
ans=[water[0],0]
mconc=0
sugar=[]
for x in water:
    sugar.append(min(F-x,(x*E//100)))
for w,s in zip(water,sugar):
    for i in range(s//C+1):
        j=(s-C*i)//D
        cap=(C*i+D*j)
        if(cap/(w+cap))*100>mconc:
            mconc=(cap/(w+cap))*100
            ans=[w+cap,cap]
print(*ans)

Submission status: Accepted

Solution code:
# ABC074C - Sugar Water
# input
a, b, c, d, e, f = list(map(int, input().rstrip().split()))
A = a * 100
B = b * 100

# default values
x, y = min(a, b) * 100, 0  # density could be 0%
dens = y / x


# exhaustive search
for i in range(f // A + 1):
    for j in range(((f - A * i) // B) + 1):
        if i == 0 and j == 0:
            continue
        water = i * A + j * B
        rest = f - water
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                total = water + sugar

                if sugar / total > e / (e + 100):  # compare to e (the max density)
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x, y = total, sugar
print(x, y)

Submission status: Accepted

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

W = []
for i in range(f+1):
    for j in range(f+1):
        w = a*i + b*j
        if w <= f and w > 0:
            W.append(w)
S = []
for i in range(f+1):
    for j in range(f+1):
        s = c*i + d*j
        if s <= f:
            S.append(s)

cmax = -1
solubility = e/(e+100)
argmax = 0, 0

for w in W:
    for s in S:
        if w+s > f:
            continue

        concentration = s/(w+s)

        if cmax < concentration <= solubility:
            cmax = s/(w+s)
            argmax = w+s, s

print(*argmax)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans=0
tmp=[str(100*a),'0']
for i in range(1,2**4):
  l=[0]*4
  water=0
  sugar=0
  for j in range(4):
    if i>>j&1:
      l[j]=1
  if l[0]==1:
    water+=100*a
  if l[1]==1:
    water+=100*b
  if water==0:
    pass
  else:
    rest=f-water
    if rest<=0 or (l[2]==l[3]==0):
      pass
    else:
      max_sugar=e*(water//100)
      if l[2]==1 and l[3]==0:
        sugar+=c*(min(rest,max_sugar)//c)
      elif l[3]==1 and l[2]==0:
        sugar+=d*(min(rest,max_sugar)//d)
      elif l[2]==l[3]==1:
        d_max=min(rest,max_sugar)//d
        t=d*d_max
        for i in range(d_max,-1,-1):
          REST=rest-i*d
          Max_sugar=max_sugar-i*d
          t_max=i*d+c*(min(REST,Max_sugar)//c)
          t=max(t,t_max)
        sugar+=t
      tot=sugar+water
      if sugar/tot>ans:
        ans=sugar/tot
        tmp=[str(tot),str(sugar)]
print(' '.join(tmp))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dp = [[False]*(F-100*i+1) for i in range(F//100+1)]
dp[0][0] = True
dp[A][0] = True

for i in range(A,F//100+1):
    for j in range(C,F-100*i+1):
        if i < B and j < D:
            if (dp[i-A][j] or dp[i][j-C]) and j<=i*E:
                dp[i][j] = True
        elif i >= B and j < D:
            if (dp[i-A][j] or dp[i-B][j] or dp[i][j-C]) and j<=i*E:
                dp[i][j] = True
        elif i < B and j >= D:
            if (dp[i-A][j] or dp[i][j-C] or dp[i][j-D]) and j<=i*E:
                dp[i][j] = True
        else:
            if (dp[i-A][j] or dp[i-B][j] or dp[i][j-C] or dp[i][j-D]) and j<=i*E:
                dp[i][j] = True

#print(dp)
#print(dp[5])
#print(dp[5][500])

mi = A
mj = 0
for i in range(F//100+1):
    for j in range(F-100*i+1):
        if dp[i][j] and (j*(100*mi+mj) > mj*(100*i+j)):
            mi = i
            mj = j
            #print(mi,mj)
print(100*mi+mj,mj)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
su=[False]*(f+1)
wa=[False]*(f+1)
a*=100
b*=100
e=(100*e)/(100+e)
for i in range(f+1):
    for j in range(f+1):
        if i*c+j*d<=f:
            su[i*c+j*d]=True
        if i*a+j*b<=f:
            wa[i*a+j*b]=True
ans=-1
x,y=a,0
for i in range(1,f+1):
    for j in range(f+1):
        if wa[i] and su[j] and i+j<=f and ans<=100*j/(i+j)<=e:
            ans=100*j/(i+j)
            x,y=i,j
print(x+y,y)

Submission status: Accepted

Solution code:
from bisect import bisect_left 
#bisect_left(a,x):a[i]>=xとなるような最小のi.
#昇順ソートされたリストaに昇順を崩さずxを挿入できる位置s(0-index)を返す.
#a=[1,3,5,7,9,11,13,15,17,19]
#s = bisect_left(a,4)
#s=2
a,b,c,d,e,f=map(int,input().split())
wa=set()
a*=100
b*=100
for i in range((f+a-1)//a+1):
    for j in range((f+b-1)//b+1):
        if 1<=i*a+j*b<=f:
            wa.add(i*a+j*b)
su=set()
e=100*e/(100+e)
x=int(f*e//100)
for i in range((x+c-1)//c+1):
    for j in range((x+d-1)//d+1):
        if i*c+j*d<=x:
            su.add(i*c+j*d)
su=sorted(list(su))
# print(wa)
# print(su)
ans=0
x,y=0,0
e+=0.001
f+=0.001
for i in wa:
    # print(i,su[bisect_left(su,f-i)-1],su[bisect_left(su,e*i/(100-e))-1])
    p=min(bisect_left(su,f-i),bisect_left(su,e*i/(100-e)))
    if p>0:
        if ans<=su[p-1]/(i+su[p-1]):
            ans=su[p-1]/(i+su[p-1])
            x,y=i,su[p-1]
print(max(x+y,a),y)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def v(a: int, b: int, c: int):
    if a < b:
        a, b = b, a
    if c % a == 0:
        return c
    minr = c
    for va in range(c // a + 1):
        minr = min(minr, (c - va * a) % b)
        if minr == 0:
            break
    return c - minr


def solve(A: int, B: int, C: int, D: int, E: int, F: int):
    ansa = A * 100
    anss = 0
    for w in range(1, F // 100 + 1):
        w2 = v(B, A, w)
        if w != w2:
            continue
        s = min(w2 * E, F - w2 * 100)
        s2 = v(D, C, s)
        a2 = s2 + w2 * 100
        if a2 > F:
            continue
        # anss / ansa < s2 / a2
        if anss * a2 < ansa * s2:
            ansa, anss = a2, s2
    print(ansa, anss)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    E = int(next(tokens))  # type: int
    F = int(next(tokens))  # type: int
    solve(A, B, C, D, E, F)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
density = 0
for i in range(F//(100*A) +1):
    for j in range((F-100*A*i)//(100*B)+1):
        water = 100*A*i + 100*B*j
        if water == 0:
            continue
        for k in range((F-water)//C+1):
            for l in range((F-water-C*k)//D+1):
                sugar = C*k + D*l
                if density <= sugar/(sugar + water) and sugar <= (E/100)*water:
                    density = sugar/(sugar + water)
                    ans = [sugar+water, sugar]
print(ans[0], ans[1])

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	a, b, c, d, e, f = IN()
	mm=f
	ww_list=[0]*(mm+1)
	ww_list[0]=1
	for i, is_ok in enumerate(ww_list):
		if is_ok == 1:
			if i+(a*100) <= mm:
				ww_list[i+(a*100)]=1
			if i+(b*100) <= mm:
				ww_list[i+(b*100)]=1
				
	max_noudo=0
	ret_sw=a*100
	ret_suger=0
	for wv, is_ok_w in enumerate(ww_list):
		if is_ok_w == 0:
			continue
		suger_limit=e*(wv//100)
		ok_s=[0]*(suger_limit + 1)
		ok_s[0]=1
		max_suger=0
		for i, is_ok in enumerate(ok_s):
			if is_ok == 1:
				if i + c <= suger_limit and (wv+i+c) <= f:
					ok_s[i+c]=1
					max_suger=max(max_suger, i+c)
				if i+d <= suger_limit and (wv+i+d) <= f:
					ok_s[i+d]=1
					max_suger = max(max_suger, i+d)
		if wv == 0:
				continue
			
		suger_noudo=((100*max_suger)/(wv+max_suger))
		if max_noudo < suger_noudo:
			max_noudo=suger_noudo
			ret_sw = wv+max_suger
			ret_suger = max_suger
	print(ret_sw, ret_suger)
	return 
				
		
	
	

	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
res=-1
ans=[0,0]
s1=set()
s2=set()
for x in range(0,f+1,100*a):
  for y in range(0,f+1-x,100*b):
    s1.add(x+y)
for x in range(0,f+1,c):
  for y in range(0,f+1-x,d):
    s2.add(x+y)
for x in s1:
  for y in s2:
    if x*e/100>=y and 0<x+y<=f:
      tmp=y/(x+y)
      if tmp>res:
        res=tmp
        ans=[x+y,y]
print(*ans)

Submission status: Accepted

Solution code:
from itertools import product

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

max_conc = 0
res = [100*a, 0]
for w1, w2 in product(range(0, f+1, 100*a), range(0, f+1, 100*b)):
    if w1 + w2 > f or w1 == w2 == 0:
        continue
    for s1 in range(0, f-w1-w2+1, c):
        s2 = (min(f-w1-w2, (w1 + w2) // 100 * e) - s1) // d * d
        if s2 < 0:
            continue
        conc = (s1 + s2) / (w1 + w2 + s1 + s2) * 100
        if conc > max_conc:
            max_conc = conc
            res = [w1 + w2 + s1 + s2, s1 + s2]

print(' '.join(map(str, res)))

Submission status: Accepted

Solution code:
import sys 
input = sys.stdin.readline
MOD = 10**9 +7
INF = 10**9
from bisect import bisect_right

def main():
    a,b,c,d,e,f = map(int,input().split())
    a *= 100
    b *= 100
    X = set()
    Y = []
    for i in range(f//a + 1):
        for j in range((f - a * i)//b + 1):
            if i == 0 and j == 0:
                continue
            X.add(a * i + b * j)
    
    for i in range(f//c + 1):
        for j in range((f - i * c)//d + 1):
            Y.append((c * i + d * j))

    Y.sort()
    c = 0
    ans = (0,0)
    for x in X:
        lim = min(e * x // 100, f - x)
        idx = bisect_right(Y, lim)
        if idx == 0:
            continue
        else:
            y = Y[idx - 1]
            if c * (x + y) <= y:
                c = y / (x + y)
                ans = (x + y, y)
    
    print(*ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int,input().split())
 
suger_max = int(f * e/(100+e))
 
water, suger = [], [] 
 
for i in range(f//(a*100) + 1):
    for j in range(f//(b*100) + 1):
        temp = a * 100 * i + b * 100 * j
        if temp <= f and 0 < temp:
            water.append(temp)

for p in range(suger_max//c + 1):
    for q in range(suger_max//d + 1):
        if c * p + d * q <= suger_max:
            suger.append(c * p + d * q) 

z = [0, 0, 0]
for x in suger:
    for y in water:
        temp = x / (x + y) 
        if temp <= e/(100+e) and x + y <= f:
            if z[0] <= temp:
                z[0] = temp
                z[1] = x + y
                z[2] = x

print(*z[1:3])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1
 
for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar
 
print(ans0, ans1)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
w = set()
for x in range(0,f+1,100*a):
    for y in range(0,f+1-x,100*b):
        w.add(x+y)
s = set()
for x in range(0,f+1,c):
    for y in range(0,f+1-x,d):
        s.add(x+y)
ans = -1
sugerwater = 0
suger = 0
for x in w:
    for y in s:
        if  0<x+y<=f and y <= x*e/100:
            if ans < y/(x+y):
                ans = y/(x+y)
                sugerwater = x+y
                suger = y
print(sugerwater,suger)

Submission status: Accepted

Solution code:
#083c
import sys

A,B,C,D,E,F = map(int, input().split())
#水*100、水*100、砂糖、砂糖

#合計はF以下、溶け残りはダメ
#水100に対してE溶ける → 100E/(100+E) が最大値

#砂糖水の濃度は 100b/(a+b)
#水a,砂糖b

max_conc = 0
total_weight_at_max_conc = 100*A
sugar_weight_at_max_conc = 0

for h in range(0, 1+int(F/(100*A))): #F<=3000,1<=Aより 最大30回ループ
    limit_water = F - (h*100*A)
    
    for i in range(0, 1+int(limit_water/(100*B))):
        limit_total_sugar_by_weight = F - (h*100*A + i*100*B)
        limit_total_sugar_by_conc = (h*100*A + i*100*B)/100*E
        limit_total_sugar = min(limit_total_sugar_by_weight,limit_total_sugar_by_conc)
            
        for j in range(0, 1+int(limit_total_sugar/C)):
            limit_D_sugar_by_weight = F - (h*100*A + i*100*B + j*C)
            limit_D_sugar_by_conc = (h*100*A + i*100*B)/100*E - j*C
            limit_D_sugar = min(limit_D_sugar_by_weight,limit_D_sugar_by_conc) 
            
            k = int(limit_D_sugar/D) #濃度を濃くするために操作Dは限界まで行う。
            
            if h>=0 and i>=0 and j>=0 and k>=0:
                a = h*100*A + i*100*B
                b = j*C + k*D
                total_weight = a + b
                
                #print(h,i,j,k)
                #print(a,b)
                
                if a + b != 0:
                    concentration = 100*b/(a+b)

                    if concentration > max_conc:
                        max_conc = concentration
                        total_weight_at_max_conc = total_weight
                        sugar_weight_at_max_conc = b

                        if max_conc == 100*E/(100+E):
                            print(total_weight_at_max_conc,sugar_weight_at_max_conc)
                            sys.exit()

print(total_weight_at_max_conc,sugar_weight_at_max_conc)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

water = []
for a in range(30):
    for b in range(30):
        w = 100*A*a + 100*B*b
        if w == 0: continue
        if w <= F: water.append(w)
        else: break

sugar = []
for c in range(3000):
    for d in range(3000):
        s = c*C + d*D
        if s <= F: sugar.append(s)
        else: break

d = 0
anss = 0
answ = 100*A
for w in water:
    for s in sugar:
        if w+s > F or w*E < 100*s:
            continue
        tmpd = (100*s)/(w+s)
        if tmpd > d:
            d = tmpd
            anss = s
            answ = w

print(anss+answ, anss)

Submission status: Accepted

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

ans = [0,0]
per = -1
#水の量を100g単位ずつ全探索
for w in range(1,f+1):
    #そのような水の取り方があるか確認
    wt = 0
    for b in range(0,w+1,B):
        if (w-b)%A == 0:
            wt = 1
            break
    if wt == 0:
        continue

    water = w*100
    sugar = min(w*E,F-water)
    if ans[0] == 0:
        ans[0] = water
    st = 0
    #砂糖として考えられる量を大きい順に0gまでに全探索
    for s in range(sugar,0,-1):
        st = 0
        for d in range(0,s+1,D):
            if (s-d)%C == 0:
                st = 1
                break
        if st == 1:
            break
    if st == 1 and s+water <= F and s/(s+water) > per:
        ans = [s+water,s]
        per = s/(s+water)

print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
water_reps = []
sugar_reps = []
for i in range(0, 3001, 100 * a):
    for j in range(0, 3001, 100 * b):
        if 0 < (i + j):
            water_reps.append(i + j)
for i in range(0, min(30 * e, 1501), c):
    for j in range(0, min(30 * e, 1501), d):
        sugar_reps.append(i + j)
water_reps = list(set(water_reps))
sugar_reps = list(set(sugar_reps))
water_reps.sort()
sugar_reps.sort()
ans = [(water_reps[0] + sugar_reps[0]), sugar_reps[0]]
for water in water_reps:
    for sugar in sugar_reps:
        if sugar <= (water // 100) * e and (water + sugar) <= f:
            conc = sugar / (water + sugar)
            if (ans[1] / ans[0]) < conc:
                ans = [(water + sugar), sugar]
print(*ans)

Submission status: Accepted

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

water = [0 for _ in range(30 + 1)]
sugar = [0 for _ in range(3000 + 1)]

water[0] = 1
sugar[0] = 1

for i in range(30):
    if water[i]:
        if i + A <= 30:
            water[i + A] = 1
        if i + B <= 30:
            water[i + B] = 1

for j in range(3000):
    if sugar[j]:
        if j + C <= 3000:
            sugar[j + C] = 1
        if j + D <= 3000:
            sugar[j + D] = 1

concentration = 0
ans = (100 * A, 0)

for i in range(31):
    if not water[i]:
        continue
    for j in range(3001):
        if not sugar[j]:
            continue
        if i + j == 0 or 100 * i + j > F or j > E * i:
            continue
        if concentration * (100 * i + j) < 100 * j:
            concentration = (100 * j) / (100 * i + j)
            ans = (100 * i + j, j)

print(*ans)

Submission status: Accepted

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

# 入れられるwaterの量ベクトル
ws = 0
while ws*a*100 <= f:
  water = ws * a
  while water*100 <= f:
    if water not in w and water != 0:
      w.append(water)
    water += b
  ws += 1

# 入れられるsugarの最大量ベクトル
ans = [1,0]
for wb in range(len(w)):
  sc = 0
  sd = 0
  ss = 0
  while sc/w[wb] <= e and sc + w[wb]*100 <= f:
    suger = sc * c
    while suger/w[wb] <= e and suger + w[wb]*100 <= f:
      if ss < suger:
        ss = suger
      suger += d
    sc += 1
  
  if ss/w[wb] >= ans[1]/ans[0]:
    ans = [w[wb] , ss]
print(' '.join(map(str,[ans[0]*100+ans[1],ans[1]])))