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()) 
x=0
y=0
#ans1 水　ans2 砂糖
ans1=1
ans2=0
for i in range(31):
    for j in range(31):
        x=100*(a*i+b*j)
        if x>f:
            continue
        if x==0:
            continue
        
        for k in range(f//c+1):
            for l in range(f//(c+d)+1):
                y=c*k+d*l
                
                if x+y>f or y/(x+y)>e/(100+e):
                    continue
                
                else:
                    if y/(x+y)>=ans2/(ans1+ans2):
                        ans1=x
                        ans2=y
                    else:
                        continue
if x+y!=0:
    print(ans1+ans2,ans2)
else:
    print(a,0)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
sato = set()
miz = set()
for i in range(F//100//A + 1):
	for j in range(F//100//B + 1):
		if i*A + j*B <= F//100:
			miz.add((i*A + j*B)*100)

for i in range(F//C + 1):
	for j in range(F//D + 1):
		if i*C + j*D <= F:
			sato.add(i*C + j*D)
miz = list(miz)
sato = list(sato)
#print(sorted(miz), sorted(sato))
node = 0
note = [100*A, 0]
for i in range(len(miz)):
	if miz[i] == 0:
		continue
	for j in range(len(sato)):
		c = 100*sato[j]/miz[i]
		q = miz[i] + sato[j]
		if c > E:
			pass
		elif q > F:
			pass
		elif c > node:
			note = [miz[i] + sato[j], sato[j]]
			node = c

print(*note)

Submission status: Accepted

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

n = 30

noudo = -1
all_s = 0
sato_s = 0

r_flag = False

for i in range(1,(f+99)//100):
    for j in range(30+1):
        if r_flag == True:
            break
        for k in range(30+1):
            if i == j*a+k*b:
                r_flag = True
                break
    if r_flag == False:
        continue
    for j in range(int((i*e)/c)+1):
        e_sato = min(f - i*100-j*c, i*e-j*c)
        d_num = e_sato // d
        tmp_sato = j*c+d_num*d
        tmp_all = tmp_sato + i*100
        tmp_noudo = (100*(tmp_sato)) / tmp_all
        #print(tmp_sato)
        if tmp_all > f:
            continue
        if noudo < tmp_noudo:
            noudo = tmp_noudo
            all_s = tmp_all
            sato_s = tmp_sato
            #print(e_sato,sato_s)
    r_flag = False


print(all_s,sato_s)

Submission status: Accepted

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

maxdense = 0
ans =[0,0]
for i in range(31):
	for j in range(31):
		for k in range(101):
			for l in range(101):
				water = (100*a)*i + (100*b)*j
				sugar = c*k + d*l

				if water == 0:
					break
				if water + sugar > f:
					break
				else:
					if water/100*e >= sugar:
						dense = 100*sugar/(water+sugar)
						if dense >= maxdense:
							maxdense = dense
							ans[0] = water + sugar
							ans[1] = sugar
print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
w=set()
s=set()
for i in range(31):
    for j in range(16):
        if 100*(A*i+B*j)<=F:
            w.add(100*(A*i+B*j))
for i in range(1501):
    for j in range(751):
        if C*i+D*j<=F/2:
            s.add(C*i+D*j)
w=list(w)
w.sort()
del w[0]
s=list(s)
s.sort()
M=-1
for i in w:
    for j in range(len(s)-1,-1,-1):
        if s[j]*100<=E*i:
            if s[j]>M*i and i+s[j]<=F:
                W,S=i,s[j]
                M=s[j]/i
print(W+S,S)

Submission status: Accepted

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

A *= 100
B *= 100

M = -float('inf')
Mwater, Msugar = 0, 0
for a in range(0, F + 1, A) :
    for b in range(0, F - a + 1, B) :
        for c in range(0, F - a - b + 1, C) :
            for d in range(0, F - a - b - c + 1, D) :
                if a + b + c + d == 0 :
                    continue
                if c + d <= (a + b) * E // 100 :
                    if 100 * (c + d) / (a + b + c + d) > M :
                        M = 100 * (c + d) / (a + b + c + d)
                        Mwater = a + b
                        Msugar = c + d
                        
print(Mwater+Msugar, Msugar)

Submission status: Accepted

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

    max_d = 0
    max_a, max_b = 100*A, 0
    for i in range(F//(100*A)+1):
        F1 = F - 100*A*i
        for j in range(F1//(100*B)+1):
            F2 = F1 - 100*B*j
            if i+j > 0:
                for k in range(min(F2,(A*i+B*j)*E)//C+1):
                    F3 = F2 - C*k
                    for l in range(min(F3,((A*i+B*j)*E-C*k))//D+1):
                        #F4 = F3 - D*l
                        #if F4 >=0 and C*k+D*l <= (A*i+B*j)*E:
                        d = (C*k+D*l) / (A*i+B*j)
                        if d > max_d:
                            max_d = d
                            max_a = C*k+D*l + 100*(A*i+B*j)
                            max_b = C*k+D*l
    return max_a, max_b


if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))

Submission status: Accepted

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

max_solvent = 0
max_solute = 0
max_strength = 0.0

for na in range(0, 31):
    for nb in range(0, 31):
        for nc in range(0, 101):
            for nd in range(0, 101):

                solute = nc * C + nd * D
                solvent = 100 * na * A + 100 * nb * B

                # if not (any([na, nb]) and any([nc, nd])):
                    # continue
                if solvent == 0:
                    break

                if solute + solvent > F:
                    # print("exceeded")
                    break

                else:
                    # if (solvent/100) * E < solute:
                    if solvent/100 * E >= solute:
                    # print("exceeded2")
                    # break
                        strength = 100 * solute / (solute + solvent)
                        # print(strength, solvent+solute, solute)
                        if max_strength <= strength:
                            max_strength = strength
                            max_solute = solute
                            max_solvent = solute + solvent

print(max_solvent, max_solute)

Submission status: Accepted

Solution code:
ope1,ope2,ope3,ope4,concent,capacity = map(int,input().split())
ope1 *= 100
ope2 *= 100
noudo = -1
check = 0
check_capacity = 0
result =""

for i in range(int(capacity / ope1)+1):
    for x in range(int( (capacity -(i*ope1)) /ope2 )+1):
        if i+x == 0:
            continue
        for y in range(int( (capacity -(i*ope1 +x*ope2)) /ope3)+1):
            for z in range( int( (capacity -(i*ope1 +x*ope2 +y*ope3) ) /ope4)+1):
                if y+z ==0:
                    if noudo < 0:
                        noudo = 0
                        result = (str(i * ope1 + x * ope2 + y * ope3 + z * ope4) + " " + str(y * ope3 + z * ope4))
                    continue
                check = (100 *(y*ope3 + z*ope4)) / ( i*ope1 + x*ope2 + y*ope3 + z*ope4)

                if check > noudo and ((i*ope1+x*ope2)/100)*concent>= y*ope3+z*ope4:
                    noudo = check
                    result = (str(i*ope1+x*ope2+y*ope3+z*ope4)+" "+str(y*ope3+z*ope4))
print(result)

Submission status: Accepted

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

x = []
y = []

k=0
i = 0
j = 0

#print(a,b,c,d,e,f)

while( 100*a*i + 100*b*j <= f ):
  while( 100*a*i + 100*b*j <= f):
    x.append(100*a*i + 100*b*j)
    j +=1
  j = 0
  i +=1
  
i = 0
j = 0
while( c*i + d*j <= f ):
  while( c*i + d*j <= f):
    y.append(c*i + d*j)
    j +=1
  j = 0
  i +=1
      
    
x = list(set(x))
y = list(set(y))

x.remove(0)
#y.remove(0)
#print( x )
#print( y )

noudo = 0
reg_i = 0
reg_j = 0

for i in range(len(x)):
  for j in range(len(y)):
    tmp_noudo = 100 * y[j] / (x[i] + y[j])
    if  tmp_noudo <= 100 * e / (100 + e) and (x[i] + y[j]) <= f:
      if noudo < tmp_noudo:
        noudo = tmp_noudo
        reg_i = i
        reg_j = j
        

print( x[reg_i]+y[reg_j] , y[reg_j] )

Submission status: Accepted

Solution code:
ope1,ope2,ope3,ope4,concent,capacity = map(int,input().split())
ope1 *= 100
ope2 *= 100
noudo = 0
check = 0
check_capacity = 0
result =str(ope1)+" "+"0"

for i in range(int(capacity / ope1)+1):
    for x in range(int( (capacity -(i*ope1)) /ope2 )+1):
        if i+x == 0:
            continue
        for y in range(int( (capacity -(i*ope1 +x*ope2)) /ope3)+1):
            for z in range( int( (capacity -(i*ope1 +x*ope2 +y*ope3) ) /ope4)+1):
                if y+z ==0:
                    continue
                check = (100 *(y*ope3 + z*ope4)) / ( i*ope1 + x*ope2 + y*ope3 + z*ope4)

                if check > noudo and ((i*ope1+x*ope2)/100)*concent>= y*ope3+z*ope4:
                    noudo = check
                    result = (str(i*ope1+x*ope2+y*ope3+z*ope4)+" "+str(y*ope3+z*ope4))
print(result)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
conc = -1
ans = (0, 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
        for c in range(0, min(w * E // 100, F - w) + 1, C):
            d = min(w * E // 100 - c, F - w - c) // D * D
            s = c + d
            if conc < s / (w + s):
                conc = s / (w + s)
                ans = (w + s, s)
print(*ans)

Submission status: Accepted

Solution code:

a, b, c, d, e, f = [ int(v) for v in input().split() ]

water_list =  [ a*100*i + b*100*j for i in range(30) for j in range(30) if  0 < a*100*i + b*100*j < f ]
water_list = sorted(list(set(water_list)))
sugar_water_list = []

def dencity(w,s):
    return (100*s) / (w+s)

for i in water_list:
    limit_sugar = min(int(e * i / 100),f-i)    
    max_sugar = 0
    for j in range(0,limit_sugar//d+1):
        limit_sugar_2 = limit_sugar - j*d
        k = limit_sugar_2 // c
        max_sugar = max(j*d+k*c,max_sugar)
    sugar_water_list.append((dencity(i,max_sugar),i+max_sugar,max_sugar))

print(sorted(sugar_water_list)[-1][1],sorted(sugar_water_list)[-1][2])

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
mxc = 0
ans = (min(100*A,100*B),0)
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                w = 100*A*i + 100*B*j
                s = C*k + D*l
                if s > E*w/100 or w+s > F or w == 0:
                    break
                if 100*s/(s+w) > mxc:
                    mxc = 100*s/(s+w)
                    ans = (s+w,s)
print(" ".join(map(str,ans)))

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

A, B, C, D, E, F = list(map(int, sys.stdin.readline().split()))

waters = set()
for a, b in itertools.product(range(31), repeat=2):
    w = A * a * 100 + B * b * 100
    if w <= F:
        waters.add(w)
waters.remove(0)
waters = list(waters)
waters.sort()

dp = [0] * (F + 1)
dp[0] = 1
for i in range(F + 1):
    if i + C < len(dp):
        dp[i + C] |= dp[i]
    if i + D < len(dp):
        dp[i + D] |= dp[i]
sugars = [i for i, s in enumerate(dp) if s]
sugars.sort()

ans_w = waters[0]
ans_s = 0
msw = 0
s = 0
for w in waters:
    while s < len(sugars) and sugars[s] * 100 <= E * w and w + sugars[s] <= F:
        s += 1
    if s - 1 < 0:
        continue
    sw = sugars[s - 1] / (w + sugars[s - 1])
    if sw > msw:
        msw = sw
        ans_w = w
        ans_s = sugars[s - 1]
print(ans_w + ans_s, ans_s)

Submission status: Accepted

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


cap = e / (100 + e)
max_noudo = 0
sugar_ans, water_ans = 0, 0
for i in range(f//(100*a)+1):
    for j in range((f - (100 * a * i)) // (100 * b) + 1):
        water = 100 * (i * a + j * b)
        for k in range(((i * a + j * b)*e)//c+1):
            for l in range(((i * a + j * b)*e - k*c)//d+1):
                sugar = k * c + l * d
                if f < water + sugar or water == 0:
                    continue
                else:
                    noudo = sugar / (water + sugar)
                    if max_noudo <= noudo <= cap:
                        max_noudo = noudo
                        sugar_ans = sugar
                        water_ans = water
print(water_ans+sugar_ans, sugar_ans)

Submission status: Accepted

Solution code:

#%%
import itertools
import time
A, B, C, D, E, F = map(int,input(). split())

st = time.time()

l = list(itertools.product(range(31), repeat=2))
water = []
for i in range(len(l)):
    tmp = 0
    tmp += 100 * A * l[i][0]
    tmp += 100 * B * l[i][1]
    if tmp <= 3000:
        water.append(tmp)
l = list(itertools.product(range(1501), repeat=2))
water = list(set(water))

sugar = []
for i in range(len(l)):
    tmp = 0
    tmp += C * l[i][0]
    tmp += D * l[i][1]
    if tmp <= 1500:
        sugar.append(tmp)
sugar = list(set(sugar))

#print(len(water))
#print(len(sugar))

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

ans.sort(key=lambda x:x[2])

#print(ans)

print(ans[-1][0], ans[-1][1])







ed = time.time()
#print(ed-st)

Submission status: Accepted

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

X = []
for i in range(F // (100 * A) + 1):
	for j in range((F - 100 * A * i) // (100 * B) + 1):
		X.append(100 * A * i + 100 * B * j)

Y = []
for i in range(F // C + 1):
	for j in range((F - C * i) // D + 1):
		Y.append(C * i + D * j)

concentrationMAX = 0
ans = [100 * A,0]

for i in X:
	for j in Y:
		if i + j > 0:
			if i + j <= F:
				if i // 100 * E >= j:
					if j / (i + j) > concentrationMAX:
						concentrationMAX = j / (i + j)
						ans[0] = i + j
						ans[1] = j

print(ans[0],end=' ')
print(ans[1])

Submission status: Accepted

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
# 水水砂砂濃ビ
# 1 2 10 20 15 200
A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
ws = set([])
ss = set([])
ans = [A, 0]
for i in range(F // A + 1):
    for j in range((F - A * i) // B + 1):
        if 0 < A * i + B * j <= F:
            ws.add(A * i + B * j)
for i in range(F // C + 1):
    for j in range((F - C * i) // D + 1):
        if 0 < C * i + D * j <= F:
            ss.add(C * i + D * j)
for i in ws:
    for j in ss:
        if i + j <= F and j / i <= E / 100:
            if ans[1] / ans[0] < j / (i + j):
                ans = [i+j, j]
print(str(ans[0])+' '+str(ans[1]))

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

A_max = int(F / (100*A))
B_max = int(F / (100*B))
AB = []

for a in range(1, A_max+1):
    for b in range(B_max+1):
        if 100*A*a + 100*B*b > F: break
        AB.append(100*A*a + 100*B*b)

AB = sorted(set(AB))
S_max = int(AB[-1] * E / 100)
C_max = int(S_max / C)
D_max = int(S_max / D)

max_ab = AB[-1]
max_cd = 0
max = 0

for ab in AB:
    S = ab * E / 100
    for c in range(C_max+1):
        for d in range(D_max+1):
            cd = C*c + D*d
            if cd > S or ab + cd > F: break
            if cd / (ab + cd) > max:
                max_ab = ab
                max_cd = cd
                max = max_cd / (max_ab + max_cd)

print(max_ab + max_cd, max_cd)

Submission status: Accepted

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

def sol(i):
	solmax = min((i*E)//100,F-i)
	s = []
	for i in range((solmax//C)+1):
		for j in range((solmax//D)+1):
			if C*i+D*j <= solmax:
				s.append(C*i+D*j)
	s = sorted(s)
	return s[-1]

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

water = list(set(water))
suger = []
for i in range(len(water)):
	suger.append(sol(water[i]))

con = 0
ws = 0
s = 0
for k in range(len(water)):
	if con <= suger[k]/(water[k]+suger[k]):
		con = suger[k]/(water[k]+suger[k])
		ws = (water[k]+suger[k])
		s = suger[k]

print(ws,s)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
a_list = set([])
b_list = set([])
for i in range((f // a) + 1):
    for j in range((f // b) + 1):
        if 0 < ((a*i) + (b*j)) * 100 <= f:
            a_list.add(((a*i)+(b*j))*100)
for i in range((f // c) + 1):
    for j in range((f // d) + 1):
        if ((c*i) + (d*j)) <= f:
            b_list.add((c*i)+(d*j))
ans = 0
ans_1 = 0
ans_2 = 0
for aa in a_list:
    for bb in b_list:
        if (aa + bb <= f) & ((bb / aa) <= e * 0.01):
            if ans <= (bb / aa) * 100:
                ans = (bb / (aa)) * 100
                ans_1 = aa + bb
                ans_2 = bb
print(str(ans_1) + " " + str(ans_2))

Submission status: Accepted

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

maxVal = 0
ans = (100 * A, 0)
for aWater in range(0, F + 1, A * 100):
    for bWater in range(0, F + 1, B * 100):
        sumWater = aWater + bWater
        if sumWater == 0 or sumWater > F:
            continue
        maxSuger = sumWater * E // 100
        for cSuger in range(0, maxSuger + 1, C):
            for dSuger in range(0, maxSuger + 1, D):
                sumSuger = cSuger + dSuger
                if sumSuger + sumWater > F or sumSuger > maxSuger:
                    break
                if maxVal < sumSuger / (sumSuger + sumWater):
                    maxVal = sumSuger / (sumSuger + sumWater)
                    ans = (sumSuger + sumWater, sumSuger)

print(*ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
w=[a*i+b*j for i in range(31) for j in range(31) if 0<a*i+b*j<=f//100]
m=max(w)*e//min(c,d)+1
s=[c*i+d*j for i in range(m) for j in range(m) if 0<c*i+d*j<=max(w)*e]
w=sorted(list(set(w)))
s=sorted(list(set(s)))
mx=0
res=(min(a,b),0)
for p in w:
	for q in s:
		if p*100+q>f or q/p>e:
			continue
		r=100*q/(100*p+q)
		if mx<r:
			mx=r
			res=(p,q)
p,q=res
print(100*p+q,q)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
a,b = max(a,b),min(a,b)
c,d = max(c,d),min(c,d)
mcons = 0
ans = ""
for ia in range(f//(a*100)+1):
    for ib in range((f-ia*100*a)//(b*100)+1):
        water = a*100*ia+b*100*ib
        sglim = min(water//100*e,f-water)
        for ic in range(sglim//c+1):
            for i_d in range((sglim-c*ic)//d+1):
                if water>0:
                    suger = c*ic+d*i_d
                    cons = suger/(suger+water)
                    mcons = max(cons,mcons)
                    if mcons == cons:
                        ans = [water+suger,suger]
print(" ".join(list(map(str,ans))))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

wa = []
for a in range(0,F//(A*100)+1):
    for b in range(0,F//(B*100)+1):
        w = a*A*100 + b*B*100
        if w < F and w not in wa:
            wa.append(w)
wa.remove(0)

md = 0
sw = 0
ss = 0
limit_dens = (100*E)/(100+E)
for w in wa:
    for c in range(0,F//C+1):
        for d in range(0,F//D+1):
            s = c*C + d*D
            if w + s <= F:
                d = (100*s)/(w+s)
                if d <= limit_dens:
                    if md <= d:
                        md = d
                        sw = w+s
                        ss = s
                        if d == limit_dens:
                            print(sw, ss)
                            exit()
print(sw, ss)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

wa = []
for a in range(0,F//(A*100)+1):
    for b in range(0,F//(B*100)+1):
        w = a*A*100 + b*B*100
        if w < F and w not in wa:
            wa.append(w)
wa.remove(0)
sa = []
for c in range(0,F//C+1):
    for d in range(0,F//D+1):
        s = c*C + d*D
        if s < F and s not in sa:
            sa.append(s)
md = 0
sw = 0
ss = 0
limit_dens = (100*E)/(100+E)
for w in wa:
    for s in sa:
        if w + s <= F:
            d = (100*s)/(w+s)
            if d <= limit_dens:
                if md <= d:
                    md = d
                    sw = w+s
                    ss = s
                    if d == limit_dens:
                        print(sw, ss)
                        exit()
print(sw, ss)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

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

m = 0
sw = 0
ss = 0
for a in range(1,F//(A*100)+1):
    w = a*A*100
    for b in range(0,F//(B*100)+1):
        w += b*B*100
        for c in range(0,F//C+1):
            for d in range(0,F//D+1):
                s = c*C + d*D
                dens = (100*s)/(w+s)
                limit_dens = (100*E)/(100+E)
                if w + s <= F and dens <= limit_dens:
                    if m <= (100*s)/(w+s):
                        m = (100*s)/(w+s)
                        sw = w+s
                        ss = s
                        if dens == limit_dens:
                            print(sw, ss)
                            exit()
print(sw, ss)

Submission status: Accepted

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

max_c = 0
max_w = 0
max_s = 0

# t  = (100*e)/(100+e)

for i in range(int((f//(100*a)+1))):
  for j in range(int((f-100*a*i)//(100*b)+1)):
    x = 100*a*i+100*b*j
    for k in range(int((f-x)//c+1)):
      for l in range(int((f-x-c*k)//d+1)):
        y = c*k+d*l
        if x+y == 0 or x+y > f:
          continue
        else:
          conc = (100*y)/(x+y)
          # print(conc)
          if max_c <= conc and y <= (x*e)/100:
            max_c = conc
            max_w = x
            max_s = y
print(int(max_w+max_s), int(max_s))

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
can = []
for ai in range(31):
  for bi in range(31):
    if ai == bi == 0:
      continue
    whole = ( ai * a + bi * b ) * 100
    sugarmax = ( ai * a + bi * b ) * e
    sugarrest = sugarmax
    #f = juicemax
    juicerest = f - whole
    ci = 0
    while True:
      if juicerest < 0 or sugarrest < 0:
        break
      di = min( sugarrest , juicerest ) // d
      can.append([(ci*c+di*d)/(whole+di*d),whole+di*d,ci*c+di*d,ai,bi,ci,di,sugarrest,juicerest])
      whole += c
      sugarrest -= c
      juicerest -= c
      ci += 1
can.sort()
#print(can[-1])
print(str(can[-1][1]) + ' ' + str(can[-1][2]))

Submission status: Accepted

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

for a in range(F//(100*A)+1):
    for b in range((F-a*100*A)//(100*B)+1):
        water = a * 100 * A + b * 100 * B
        if water == 0:
            continue

        for c in range((a*A+b*B)*E//C+1):
            for d in range(((a*A+b*B)*E-c*C)//D+1):
                sugar = c * C + d * D
                if sugar + water > F:
                    continue
                conc = 100 * sugar / (water + sugar)
                answers[conc] = [str(water+sugar), str(sugar)]

max_conc = max(answers)
print(' '.join(answers[max_conc]))

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

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

"""
100gあたりEgとける

ABCDは何回でも行える
A,Bは100A, 100B

Fg以内で砂糖を溶け残らせてはいけない
水全体と砂糖の量を求める

濃度は100b/(a+b)

砂糖を細かく追加して、溶け残らないようにする？
2, 5あれば、4,5にできるので、組み合わせを全部試す？
ビーカー量が200gで、溶ける量が15gなら、最大でも30gまでしか溶けない
10, 20なら、10, 10, 10,と10, 20の組み合わせが考えられる
Cの最大回数とDの最大回数を求める
それぞれの量の組み合わせをすべて試す
例えば10回、10回なら、0,0/1,0/2,0...とすべて試す
"""
max_sugar_amount = int(F//(100+E)*E)
max_C_times = int(max_sugar_amount // C)
max_D_times = int(max_sugar_amount // D)
#  print('max sugar', max_sugar_amount, 'max c', max_C_times, 'max d', max_D_times)
#  exit()
ans_sugar = 0
ans_water = 0
ans_density = 0
def check_density(sugar, water, new_sugar, new_water):
    if water + sugar == 0:
        return True 
    density = (100*sugar) / (water+sugar)
    new_density = (100*new_sugar) / (new_water + new_sugar)
    return density < new_density


for i in range(0, max_C_times+1):
    #  print('i', i)
    if max_D_times == 0:
        sugar_amount = i*C
        if sugar_amount > max_sugar_amount:
            break
        else:
            # 溶け切る場合
            #  print('溶け切る')
            water_limit = F - sugar_amount
            min_water_amount = sugar_amount / E * 100
            #  print(sugar_amount, min_water_amount)
            max_A_times = int(water_limit // (A*100))
            max_B_times = int(water_limit // (B*100))
            #  print('maxA', max_A_times)
            for k in range(1, max_A_times+1):
                if max_B_times == 0:
                    # 水Bはいれられないとき
                    water = k*100*A
                    if water_limit >= water >= min_water_amount:
                        # 水の量が砂糖を溶かすのに十分 # 水量がこえていない
                        if check_density(ans_sugar, ans_water, sugar_amount, water):
                            ans_sugar = sugar_amount
                            ans_water = water
                else:
                    for l in range(0, max_B_times+1):
                        water = k*100*A + l*100*B
                        if water_limit >= water >= min_water_amount:
                            # 水の量が砂糖を溶かすのに十分
                            if check_density(ans_sugar, ans_water, sugar_amount, water):
                                ans_sugar = sugar_amount
                                ans_water = water

    for j in range(0, max_D_times+1):
        #  print(j)
        sugar_amount = i*C + j*D
        if sugar_amount > max_sugar_amount:
            break
        else:
            water_limit = F - sugar_amount
            min_water_amount = sugar_amount / E * 100
            max_A_times = int(water_limit // (A*100))
            max_B_times = int(water_limit // (B*100))
            for k in range(1, max_A_times+1):
                if max_B_times == 0:
                    water = k*100*A
                    if water_limit >= water >= min_water_amount:
                        # 水の量が砂糖を溶かすのに十分 # 水量がこえていない
                        if check_density(ans_sugar, ans_water, sugar_amount, water):
                            ans_sugar = sugar_amount
                            ans_water = water
                else:
                    for l in range(max_B_times+1):
                        water = k*100*A + l*100*B
                        if water_limit >= water >= min_water_amount:
                            if check_density(ans_sugar, ans_water, sugar_amount, water):
                                ans_sugar = sugar_amount
                                ans_water = water
print(ans_water + ans_sugar, ans_sugar)

Submission status: Accepted

Solution code:

a,b,c,d,e,f = map(int,input().split())
A = 100*a
B = 100*b

x,y = min(A,B),0
dens = y / x

for i in range(f // A + 1):
    for j in range((f - A * i) // B + 1):
        if i==0 and j==0:
            continue
        water = A*i + B*j
        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 = sugar + water
                if sugar / total > e / (100+e):
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x,y = total,sugar
print(x,y)