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

i=0
mizu=[]
while a*i*100<=f:
    j=0
    while b*j*100<=f:
        if a*i+b*j!=0 and (not (a*i+b*j)*100 in mizu):
            mizu.append((a*i+b*j)*100)
        j+=1
    i+=1

# print(mizu)

i=0
sato=[]
while c*i<=f:
    j=0
    while d*j<=f:
        if not c*i+d*j in sato:
            sato.append(c*i+d*j)
        j+=1
    i+=1
# print(sato)

ans=[sato[0],mizu[0]]
for i in range(len(mizu)):
    for j in range(len(sato)):
        if sato[j]+mizu[i]<=f and sato[j]*100<=e*mizu[i]:
            if ans[0]/(ans[0]+ans[1])<sato[j]/(mizu[i]+sato[j]):
                ans=[sato[j], mizu[i]]

print("{0} {1}".format(ans[0]+ans[1], ans[0]))

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int, input().split())
cnt_A=0
cnt_B=0
cnt_C=0
cnt_D=0
max_noudo=0
water=A*100
sugar=0
while cnt_A*100*A <= F:
  cnt_B=0
  while cnt_B*100*B <= F-cnt_A*100*A:
    cnt_C=0
    while cnt_C*C <= F-cnt_A*100*A-cnt_B*100*B:
      cnt_D=0
      while cnt_D*D <= F-cnt_A*100*A-cnt_B*100*B-cnt_C*C:
        if (cnt_A*A+cnt_B*B)*E >= cnt_C*C+cnt_D*D >0:
          if max_noudo < 100*(cnt_C*C+cnt_D*D)/(cnt_A*A+cnt_B*B):
            max_noudo = 100*(cnt_C*C+cnt_D*D)/(cnt_A*A+cnt_B*B)
            water=cnt_A*A*100+cnt_B*B*100+cnt_C*C+cnt_D*D
            sugar=cnt_C*C+cnt_D*D
        cnt_D+=1
      cnt_C+=1
    cnt_B+=1
  cnt_A+=1

print(water,sugar)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int, input().split())
cnt_A=0
cnt_B=0
cnt_C=0
cnt_D=0
max_noudo=0
water=A*100
sugar=0
while cnt_A*100*A <= F:
  cnt_B=0
  while cnt_B*100*B <= F-cnt_A*100*A:
    cnt_C=0
    while cnt_C*C <= F-cnt_A*100*A-cnt_B*100*B:
      cnt_D=0
      while cnt_D*D <= F-cnt_A*100*A-cnt_B*100*B-cnt_C*C:
        if (cnt_A*A+cnt_B*B)*E >= cnt_C*C+cnt_D*D >0:
          if max_noudo < 100*(cnt_C*C+cnt_D*D)/(cnt_A*A+cnt_B*B):
            max_noudo = 100*(cnt_C*C+cnt_D*D)/(cnt_A*A+cnt_B*B)
            water=cnt_A*A*100+cnt_B*B*100+cnt_C*C+cnt_D*D
            sugar=cnt_C*C+cnt_D*D
        cnt_D+=1
      cnt_C+=1
    cnt_B+=1
  cnt_A+=1
 
print(water,sugar)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
solve = E/(100+E)
ans = [0,0,0]
for i in range(int(F//100//A)+1):
    for j in range(int((F-A*100*i)//100//B)+1):
        for k in range(int((F-A*100*i-B*100*j)//C)+1):
            for l in range(int((F-A*100*i-B*100*j-C*k)//D)+1):
                if  i!=0 or j!=0:
                    can = (C*k+D*l)/(A*100*i+B*100*j+C*k+D*l)
                    if solve>=can>=ans[0]:
                        
                        ans[0],ans[1],ans[2] = can,A*100*i+B*100*j+C*k+D*l,C*k+D*l

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

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
ansS = 0
ansT = 0
rate = -1
for a in range(F // (A*100)+1):
    di_a = F - A*a*100
    for b in range(di_a // (B*100) + 1):
        di_b = di_a - B*b*100
        for c in range(di_b//C+1):
            di_c = di_b - c*C
            for d in range(di_c //D+1):
                if (a+b != 0 and E*(a*A+b*B) >= c*C+d*D):
                    total = 100*(A*a+B*b)+c*C+d*D
                    sugers = c*C+d*D
                    if(rate < sugers/total and total <= F):
                        rate = sugers/total
                        ansT = total
                        ansS = sugers

print(ansT, ansS)

Submission status: Accepted

Solution code:
s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
e = int(s[4]);
f = int(s[5]);
ans = 0;
ans_w = 100*a;
ans_s = 0;
for i in range(0,f,100*a) :
	for j in range(0,f,100*b) :
		#if 100 * a * i + 100 * b * j <= f :
			for k in range(0, f - i - j,c) :
				for l in range(0, f - i - j,d) :
					if i != 0 or j != 0 or k != 0 or l != 0 :
						#print(i,j,k,l,100*( k + l )//( i + j + k + l ));
						if i+j+k+l <= f and  k + l <= e * ( i + j )//100 :
							if 100*( k + l )/( i + j + k + l ) > ans :
								ans = 100 *( k + l )/( i + j + k + l );
								ans_w = i + j;
								ans_s = k + l;
print(ans_w+ans_s,ans_s);

Submission status: Accepted

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

dil=0
ans=(0,0)
for i in range(F//(A*100)+1):
    F_remainA=F-i*A*100
    for j in range(F_remainA//B*100+1):
        F_remainB=F_remainA-j*B*100   
        for k in range(F_remainB//C+1):
            F_remainC=F_remainB-k*C
            for l in range(F_remainC//D+1):
                if i+j!=0 and k+l!=0:
                    if (k*C+l*D)/(i*A*100+j*B*100+k*C+l*D) > dil and (k*C+l*D)/(i*A+j*B)<=E:
                        dil=(k*C+l*D)/(i*A*100+j*B*100+k*C+l*D)
                        ans=(100*(i*A+j*B)+k*C+l*D, k*C+l*D)

if dil==0:
    print(min(A,B)*100, 0)
else:
    print(*ans)

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

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

max_density = -1
max_total = 0
max_sugar = 0
for i in range(F // 100):
    for j in range(F // 100):
        if i == 0 and j == 0:
            continue

        water = 100*A*i + 100*B*j
        if water > F:
            break

        left = F - water
        sugar_limit = min((A*i+B*j)*E, F - water)

        msugar = 0
        for k in range(sugar_limit // C + 1):
            for l in range(sugar_limit // D + 1):
                sugar = C * k + D * l
                if sugar > sugar_limit:
                    break
                if sugar > msugar:
                    msugar = sugar

        density = 100 * msugar / (msugar + water)
        if density > max_density:
            max_density = density
            max_total = msugar + water
            max_sugar = msugar

print(max_total, max_sugar)

Submission status: Accepted

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

ma_per = -1
ma_w = -1
ma_s = -1

for aa in range(31):
    for bb in range(31):
        for cc in range(101):
            for dd in range(101):
                w = 100 * aa * a + 100 * bb * b
                s = cc * c + dd * d
                if (w + s) > f:
                    break
                if s > (w * e / 100):
                    break
                if w+s == 0:
                    break
                per = 100 * s / (w + s)
                if per > ma_per:
                    ma_per = per
                    ma_w = w
                    ma_s = s

print("{0} {1}".format(ma_w + ma_s, ma_s))

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
a *= 100
b *= 100
water = []
sugar = []
for i in range(1 + f // a):
    for j in range(1 + f // b):
        if i * a + j * b <= f:
            water.append(i * a + j * b)
for i in range(1 + f // c):
    for j in range(1 + f // d):
        if i * c + j * d <= f:
            sugar.append(i * c + j * d)
max_sugar_percent = 0
max_sugarwater = 0
max_sugar = 0
water.sort()
sugar.sort()
for w in water:
    for s in sugar:
        if w + s > f:
            break
        if s > e * w / 100:
            break
        sugar_percent = w and (100 * s) / (w + s)
        if sugar_percent >= max_sugar_percent:
            max_sugar_percent = sugar_percent
            max_sugar = s
            max_sugarwater = w + s
print(max_sugarwater, max_sugar)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = [int(i) for i in input().split()]
max_density = 0.0
water = 0
sugar = 0
for i_1 in range(f//(a*100)+1):
    for i_2 in range((f-100*a*i_1)//(b*100)+1):
        for i_3 in range(min(((i_1*a+i_2*b)*e)//c , (f-(i_1*100*a+i_2*100*b))//c)+1):
            i_4 = min((((i_1*a+i_2*b)*e)-i_3*c)//d , (f-(i_1*100*a+i_2*100*b+i_3*c))//d)
            if i_1 == 0 and i_2 == 0:
                break
            if (i_3*c + i_4*d)/(i_1*100*a+i_2*100*b+i_3*c + i_4*d) >= max_density:
                max_density = (i_3*c + i_4*d)/(i_1*100*a+i_2*100*b+i_3*c + i_4*d)
                water = i_1*100*a+i_2*100*b
                sugar = i_3*c + i_4*d
print(water+sugar, sugar)

Submission status: Accepted

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

# 濃度,砂糖水の質量、溶けている砂糖の質量
ans = (0, 0, 0)

# まず水の量を考える
for i in range(0, f // (100 * a) + 1):
    for j in range(0, f // (100 * b) + 1):
        if i == 0 and j == 0:
            continue

        # 水の量だけで上限を超えたら終了
        waterV = 100 * a * i + 100 * b * j
        if waterV > f:
            break

        # トータル質量の残り
        leftVolume = f - waterV
        # 砂糖として入れられる最大値
        satouMax = min((a*i + b*j) * e, leftVolume)  # これを作れたら最大

        # 砂糖として入れられる最大値
        sMax = 0
        for si in range(0, satouMax // c + 1):
            blnOk = False
            for sj in range(0, satouMax // d + 1):
                satou = c * si + d * sj
                if satou == satouMax:
                    sMax = satou
                    blnOk = True
                    break
                if satou > satouMax:
                    break
                sMax = max(sMax, satou)

            if blnOk:
                break

        # 濃度計算
        noudo = 100 * sMax / (waterV + sMax)

        if ans[0] <= noudo:
            ans = (noudo, waterV+sMax, sMax)

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

Submission status: Accepted

Solution code:
import itertools

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

WF = F//100+1

water = [False] * (WF+1+30)
sugar = [False] * (F+1+30)

water[0] = True
sugar[0] = True

for n in range(WF):
  if water[n]:
    water[n+A] = True
    water[n+B] = True
for n in range(F):
  if sugar[n]:
    sugar[n+C] = True
    sugar[n+D] = True

water = set(100*x for x in range(1,1+WF) if water[x])
sugar = set(x for x in range(1+F) if sugar[x])

# at most 30 * 3000なので全てやる
ans_per = -1
for w, s in itertools.product(water, sugar):
  if w//100*E < s:
    continue
  if w+s > F:
    continue
  x = s/(w+s)
  if x > ans_per:
    ans_per = x
    ans_w = w
    ans_s = s

print(ans_w + ans_s, ans_s)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
dp1=[0]*31
dp1[0]=1
m=0
for i in range(1,31):
    if i-A>=0:
        dp1[i]=max(dp1[i],dp1[i-A])
        m=(i)*E
    if i-B>=0:
        dp1[i]=max(dp1[i],dp1[i-B])
        m=(i)*E
dp2=[0]*(1+m)
dp2[0]=1
for i in range(m+1):
    if i-C>=0:
        dp2[i]=max(dp2[i],dp2[i-C])
    if i-D>=0:
        dp2[i]=max(dp2[i],dp2[i-D])
ans=0
w=0
s=0
for i in range(1,31):
    if dp1[i]==0:
        continue
    for j in range(1+m):
        if dp2[j]==0:
            continue
        if j<=i*E and i*100+j<=F:
            if ans<100*j/(i*100+j):
                ans=100*j/(i*100+j)
                w=100*i
                s=j
if s==0:
    print(min(A,B)*100,0)
    quit()
print(w+s,s)

Submission status: Accepted

Solution code:
def main():
    A, B, C, D, E, F = map(int, input().split())
    xl = []
    yl = []
    for i in range(31):
        for j in range(31):
            x = 100 * A * i + 100 * B * j
            if F >= x and x > 0 and x not in xl:
                xl.append(x)
    for i in range(F):
        for j in range(F):
            y = C * i + D * j
            if F >= y and y > 0 and y not in yl:
                yl.append(y)
    ax = 3001
    ay = 0
    for x in xl:
        for y in yl:
            if F >= x + y and E / (E + 100) >= y / (x + y) and y / (x + y) > ay / (ax + ay):
                ax = x
                ay = y
    if ax == 3001:
        print(100 * A, 0, end=' ')
    else:
        print(ax + ay, ay, end=' ')


main()

Submission status: Accepted

Solution code:
#C
A,B,C,D,E,F=map(int,input().split())
density=0
Ans1=0
Ans2=0
water=set() 
sugar=set()

bm=F//(100*B)
for i in range(bm+1):
    rw=F-100*i*B
    am=rw//(100*A)
    for j in range(am+1):
        water.add(100*i*B+100*j*A)

dm=F//D
for i in range(dm+1):
    rs=F-i*D
    cm=rs//C
    for j in range(cm+1):
        sugar.add(i*D+j*C)
sugar=sorted(sugar)
water=sorted(water)
for s in sugar:
    for w in water:
        if w/100*E>=s and s+w<=F and s+w!=0:
            den=s/(s+w)
            if den>=density:
                density=den
                Ans1=s+w
                Ans2=s
            else:
                break
print(Ans1,Ans2)

Submission status: Accepted

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

water = 0
sugar = 0
density = 0

for i in range(31):
    for j in range(31):
        w = 100 * a * i + 100 * b * j
        for k in range(101):
            for l in range(101):
                s = c * k + d * l
                if w == 0:
                    break
                elif w + s > f:
                    break
                else:
                    if water == 0:
                        water = w + s
                        sugar = s
                        density = s/(w+s)
                    
                    if density < s/(w+s) <= m_dens:
                        water = w + s
                        sugar = s
                        density = s/(w+s)

print(water, sugar)
#print(density)
#print(m_dens)

Submission status: Accepted

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

water,sugar = -1,-1
t = 0
for i in range(31):
    for j in range(31):
        for p in range(F//C):
            for q in range(F//D):
                k = i*A + j*B
                pq = p*C + q*D
                if k == 0:
                    break

                if k*100 + pq > F:
                    break

                if k*E >= pq:
                    if t <= (100*pq)/(100*k + pq):
                        t = (100*pq)/(100*k + pq)
                        water,sugar = 100*k+pq,pq

print(water,sugar)

Submission status: Accepted

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


def concentration(water, suger):
    if water * E/100 < suger or water + suger == 0:
        return 0
    return (100 * suger/(water + suger))

lst_w = []
limit_w = (F+A*100-1)//(A*100)
for i in range(limit_w):
    for j in range(limit_w):
        if 100 * (A * i + B * j) <= F:
            lst_w += [100 * (A * i + B * j)]

lst_s = []
limit_s = (F+C-1)//C
for i in range(limit_s):
    for j in range(limit_s):
        if C* i + D * j <= F:
            lst_s += [C * i + D * j]

# print (lst_w)
# print (lst_s)
set_w = set(lst_w)
set_s = set(lst_s)

# print (set_w)
# print (set_s)

ans = 0
ans_total = 0
ans_suger = 0
for water in set_w:
    for suger in set_s:
        if water + suger <= F:
            a = concentration(water, suger)
            if ans < a:
                ans = a
                ans_total = water + suger
                ans_suger = suger
            if ans == 50:
                print (ans_total, ans_suger)
                sys.exit()

if ans == 0:
    print (A * 100, 0)
else:
    print (ans_total, ans_suger)

# print (ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
ans=[100,-1]
e=E/(100+E)
W=[a+b for a in range(0,F+1,100*A) for b in range(0,F+1,100*B) if a!=0 or b!=0]
for w in W:
    for c in range(0,F-w+1,C):
        for d in range(0,F-w-c+1,D):
            s=c+d
            if w+s>F or s/(w+s)>e:break
            elif ans[1]/ans[0]<s/(w+s)<=e:
                ans=[w+s,s]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
water = []
sugar = []
for i in range(1+F//A):
    for j in range(1+F//B):
        if i * A + j * B <= F:
            water.append(i * A + j * B)
for i in range(1+F//C):
    for j in range(1+F//D):
        if i * C + j * D <= F:
            sugar.append(i * C + j * D)
max_sugar_percent = 0
max_sugar_water = 0
max_sugar = 0
water.sort()
sugar.sort()
for i in water:
    for j in sugar:
        if i + j > F:
            break
        if j > E * i / 100:
            break
        sugar_percent = i and (100 * j) / (i + j)
        if sugar_percent >= max_sugar_percent:
            max_sugar_percent = sugar_percent
            max_sugar = j
            max_sugar_water = i + j
print(max_sugar_water, max_sugar)

Submission status: Accepted

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

water = []
sugar = []

for i in range(1 + f // a):
    for j in range(1 + f // b):
        if i * a + j * b <= f:
            water.append(i * a + j * b)

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

max_sugar_percent = 0
max_sugarwater = 0
max_sugar = 0

water.sort()
sugar.sort()

for w in water:
    for s in sugar:
        if w + s > f:
            break

        if s > e * w / 100:
            break

        sugar_percent = w and (100 * s) / (w + s)
        if sugar_percent >= max_sugar_percent:
            max_sugar_percent = sugar_percent
            max_sugar = s
            max_sugarwater = w + s

print(max_sugarwater, max_sugar)

Submission status: Accepted

Solution code:
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor, mul

import sys
#input = sys.stdin.readline

def inpl(): return list(map(int, input().split()))
A, B, C, D, E, F = inpl()
waters = [100*A*a + 100*B*b for a in range(30//A + 1) for b in range((30-A*a)//B + 1)]
sugars = [C*c + D*d for c in range(3000//C + 1) for d in range((3000-C*c)//D + 1)]

waters = sorted(set(waters))[1:]
sugars = sorted(set(sugars))


def check(m):
    if m > E:
        return False, None, None
    for water in waters:
        sugar_ix = bisect_left(sugars, m*water/(100-m))
        if (sugar_ix == len(sugars)):
            continue
        sugar = sugars[sugar_ix]
        if sugar + water <= F and sugar <= water*E//100:
            return True, sugar, water
    else:
        return False, None, None

OK = 0
NG = E + 1

for _ in range(1000):
    mid = (OK+NG)/2
    if check(mid)[0]:
        OK = mid
    else:
        NG = mid

_, sugar, water = check(OK)
print(sugar+water, sugar)

Submission status: Accepted

Solution code:
from bisect import bisect, bisect_left
from collections import Counter
from functools import reduce
from itertools import accumulate
from operator import itemgetter, xor, mul

import sys
#input = sys.stdin.readline

def inpl(): return list(map(int, input().split()))
A, B, C, D, E, F = inpl()
waters = [100*A*a + 100*B*b for a in range(30//A + 1) for b in range((30-A*a)//B + 1)]
sugars = [C*c + D*d for c in range(3000//C + 1) for d in range((3000-C*c)//D + 1)]

waters = sorted(set(waters))[1:]
sugars = sorted(set(sugars))


def check(m):
    if m > E:
        return False, None, None
    for water in waters:
        sugar_ix = bisect_left(sugars, m*water/(100-m))
        if (sugar_ix == len(sugars)):
            continue
        sugar = sugars[sugar_ix]
        if sugar + water <= F and sugar <= water*E//100:
            return True, sugar, water
    else:
        return False, None, None

OK = 0
NG = E + 1

for _ in range(1000):
    mid = (OK+NG)/2
    if check(mid)[0]:
        OK = mid
    else:
        NG = mid

_, sugar, water = check(OK)
print(sugar+water, sugar)

Submission status: Accepted

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

sugar_water = -1
sugar = -1
concentration = -1

for i in range(F//(A*100)+1):
    for j in range((F-A*100*i)//(B*100)+1):
        for k in range((F-A*i*100-B*100*j)//C+1):
            for l in range((F-A*i*100-B*100*j-C*k)//D+1):
                x = i * A + j * B
                y = k * C + l * D
                if x == 0:
                    continue
                if x * E >= y and concentration < (100 * y)/(x*100+y):
                    sugar_water = 100 * x + y
                    sugar = y
                    concentration = (100 * y)/(x*100+y)

print(sugar_water,sugar)

Submission status: Accepted

Solution code:
import math
a,b,c,d,e,f=map(int,input().split())
m_suger=f*e/(100+e)
water=set()
w=math.floor(f/100/a)*a
water.add(w)
f_=f//100
while(1):
     w-=a
     if w<0:
          break
     w_=w
     while(w_<=f_):
          water.add(w_)
          w_+=b
water.remove(0)
m_rate=0
m_content=[0,0]
for w in water:
     res=f-w*100
     m_suger=min(w*e,res)
     s=math.floor(m_suger/c)*c
     while(1):
          if s<=m_suger:
               rate=s/(w+s)
               if rate>=m_rate:
                    m_rate=rate
                    m_content=[w,s]
          s-=c
          if s<0:
               break
          s_=s
          while(s_<=m_suger):
               rate=s_/(w+s_)
               if rate>=m_rate:
                    m_rate=rate
                    m_content=[w,s_]
               s_+=d
print(m_content[0]*100+m_content[1],m_content[1])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = list(map(int, input().split()))
water = []
suger = []
ans = [0, 0]
ans_max = 0
for i in range(f//100+1):
  for j in range(f//100+1):
    x = 100*(i*a+j*b)
    if x <= f and x > 0 and x not in water:
      water.append(x)
for i in range(f):
  for j in range(f):
    y = c*i + d*j
    if y <= f and y not in suger:
      suger.append(y)
ans[0] = water[0]
for i in water:
  if i == 0:
      continue
  for j in suger:
    if (i+j <= f) and (i*e >= 100*j):
      percent = (100*j)/(i+j)
      if ans_max < percent:
        ans_max = percent
        ans = [i, j]
print(sum(ans), ans[1])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
water = [(A * i + B * j) * 100 for i in range(11) for j in range(11)][1:]
sugar = [C * i + D * j for i in range(101) for j in range(101)]

ans = [100, -1]
for w in water:
    for s in sugar:
        if w + s <= F and s <= E * w // 100:
            if s / (w + s) > ans[1] / ans[0]:
                ans = [w + s, s]
            
print(*ans)

Submission status: Accepted

Solution code:
from collections import deque
import bisect

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

operation_water = [100*A, 100*B]
operation_sugar = [C, D]
water_lst = []
sugar_lst = [0]

def bfs_water():
    dq = deque()
    dq.append(0)
    while dq:
        water = dq.popleft()
        for add_water in operation_water:
            new_water = water + add_water
            if new_water <= F and new_water not in water_lst:
            	dq.append(new_water)
            	water_lst.append(new_water)
            
def bfs_sugar():
    dq = deque()
    dq.append(0)
    while dq:
        sugar = dq.popleft()
        for add_sugar in operation_sugar:
            new_sugar = sugar + add_sugar
            if new_sugar <= F/2 and new_sugar not in sugar_lst:
            	dq.append(new_sugar)
            	sugar_lst.append(new_sugar)

bfs_water()
bfs_sugar()
sugar_lst.sort()

concentration = []
for i in range(len(water_lst)):
  idx_maxmelt = bisect.bisect_right(sugar_lst, min(water_lst[i]/100*E, F-water_lst[i]))
  sugar_maxmelt = sugar_lst[idx_maxmelt-1]
  concentration.append((water_lst[i]+sugar_maxmelt, sugar_maxmelt, sugar_maxmelt/(water_lst[i]+sugar_maxmelt)))

max_concentration = sorted(concentration, key=lambda x:x[2], reverse=True)[0]
ans_weight = int(max_concentration[0])
ans_sugar = int(max_concentration[1])
print(ans_weight, ans_sugar)

Submission status: Accepted

Solution code:
w1, w2, s1, s2, sp, l = map(int, input().split())
w1 *= 100
w2 *= 100

ws = set()
for i1 in range(l // w1 + 1):
    for i2 in range(l // w2 + 1):
        if i1 * w1 + i2 * w2 <= l:
            ws.add(i1 * w1 + i2 * w2)


ss = set()
for i1 in range((l * sp // 100) // s1 + 1):
    for i2 in range((l * sp // 100) // s2 + 1):
        if i1 * s1 + i2 * s2 <= l * sp / 100:
            ss.add(i1 * s1 + i2 * s2)


maxd, maxws, maxs = 0, 0, 0
for w in ws:
    for s in ss:
        if w + s > l or w == 0 or s > w * sp / 100:
            continue

        d = s / (w + s)
        if d >= maxd:
            maxd = d
            maxws = w + s
            maxs = s

print(maxws, maxs)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
water=set({})
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        if 100*A*i + 100*B*j <= F:
            water|={100*A*i + 100*B*j}
sugar=set({})
for i in range(F//C+1):
    for j in range(F//D+1):
        if C*i + D*j <= F:
            sugar|={C*i + D*j}
water-=set({0})
max_=0
for w in water:
    for s in sugar:
        if w+s<=F and s*(100+E)<=E*(w+s) and max_*(w+s)<=s:
            max_=s/(w+s)
            ans=[w+s,s]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
max_=0
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-100*A*i-100*B*j)//C+1):
            a=E/(100+E)
            bunshi=100*A*i+100*B*j+C*k
            l=min((F-bunshi)//D,(a*bunshi-C*k)//((1-a)*D))
            if bunshi+D*l==0 or l<0:
                pass
            elif bunshi+D*l <= F and (C*k+D*l)*(100+E)<=E*(bunshi+D*l):
                if max_*(bunshi+D*l)<(C*k+D*l):
                    max_ = (C*k+D*l)/(bunshi+D*l)
                    ans = [bunshi+D*l,C*k+D*l]
            if bunshi+D*(l+1)==0 or l<0:
                pass
            elif bunshi+D*(l+1) <= F and (C*k+D*(l+1))*(100+E)<=E*(bunshi+D*(l+1)):
                if max_*(bunshi+D*(l+1))<(C*k+D*(l+1)):
                    max_ = (C*k+D*(l+1))/(bunshi+D*(l+1))
                    ans = [bunshi+D*(l+1),C*k+D*(l+1)]   
print(int(ans[0]),int(ans[1]))

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
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:
# 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 + min(c, d)), min(c, d)
x, y = min(a, b) * 100, 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):
#                if k == 0 and l == 0:
#                    continue
                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:
import sys
sys.setrecursionlimit(100000000)
A,B,C,D,E,F = [int(x) for x in input().split()]

x = []
y = []
ans_max = 0
ans = [0,0]

for i in range(F//(100*A)+1):
    for j in range((F-100*A*i)//(100*B)+1):
        water = 100*(A*i+B*j)
        if(water<=F and not water in x and water!=0):
            x.append(water)

ans[0]=x[0]

for i in range(F):
    for j in range(F):
        salt = C*i+D*j
        if(salt<=F and not salt in y):
            y.append(salt)

for i in x:
    for j in y:
        if(i==0):
            continue
        elif(100*j <= i*E and i+j <= F):
            percent = 100*j/(i+j)
            if(ans_max < percent):
                ans_max = percent
                ans = [i,j]

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

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
density = 0
for water_a in range(0,3001,a * 100):
    for water_b in range(0,3001,b * 100):
        if water_a + water_b > f:
            break
        for suger_c in range(0,3001,c):
            if water_a + water_b + suger_c > f:
                break
            for suger_d in range(0,3001,d):
                if water_a + water_b + suger_c + suger_d > f:
                    break
                if e * (water_a + water_b) - 100 * (suger_c + suger_d) < 0:
                    break
                water = water_a + water_b
                suger = suger_c + suger_d
                if water + suger == 0:
                    break
                if 1 >= suger / (water + suger) >= density:
                    sugerwater = water + suger
                    meltsuger = suger
                    density = suger / (water + suger)
print(sugerwater, meltsuger)