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())
a *= 100
b *= 100
water = set()
sugar = set()
for i in range(f//a + 1):
    for j in range((f - a*i)//b + 1):
        water.add(a*i + b*j)
ms = max(water) // 100 * e
for i in range(ms//c + 1):
    for j in range((ms - c*i)//d + 1):
        sugar.add(c*i + d*j)
def maxcon(x, y, z, w):
    if (z + w)*y >= (x + y)*w:
        return x, y
    else:
        return z, w
maxconwater = 100
maxconsugar = -1
for w in water:
    for s in sugar:
        if w // 100 * e >= s and w + s <= f:
            maxconwater, maxconsugar = maxcon(maxconwater, maxconsugar, w, s)
print(maxconwater + maxconsugar, maxconsugar)

Submission status: Accepted

Solution code:
w1, w2, s1, s2, s_max, b_max = map(int, input().split())
waters = [0]
waters_base = [0]
while len(waters_base) > 0:
    base = waters_base.pop()
    water1 = base + 100 * w1
    water2 = base + 100 * w2
    if water1 not in waters and water1 <= b_max:
        waters.append(water1)
        waters_base.append(water1)
    if water2 not in waters and water2 <= b_max:
        waters.append(water2)
        waters_base.append(water2)
waters.pop(0)
sugars = [0]
sugars_base = [0]
while len(sugars_base) > 0:
    base = sugars_base.pop()
    sugar1 = base + s1
    sugar2 = base + s2
    if sugar1 not in sugars and sugar1 <= b_max:
        sugars.append(sugar1)
        sugars_base.append(sugar1)
    if sugar2 not in sugars and sugar2 <= b_max:
        sugars.append(sugar2)
        sugars_base.append(sugar2)
max_radio = -1
result = (-1, -1)
for water in waters:
    for sugar in sugars:
        if b_max < water + sugar:
            continue
        if water // 100 * s_max < sugar:
            continue
        ratio = sugar / (water + sugar)
        if max_radio < ratio:
            max_radio = ratio
            result = (water + sugar, sugar)
print(*result)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
concent = 0
ans = []
for one in range(F//(100*A)+1):
    for two in range((F-100*A*one)//(100*B)+1):
        for three in range((F-100*A*one-100*B*two)//C+1):
            for four in range((F-100*A*one-100*B*two-C*three)//D+1):
                water = 100*A*one+100*B*two
                sugar = C*three+D*four
                all = water + sugar
                if all == 0:
                    continue
                if E*water//100 < sugar or all > F:
                    continue
                if concent < 100*sugar/all:
                    concent = 100*sugar/all
                    ans = [all,sugar]
if len(ans) == 0:
    print(str(100*A)+' '+str(0))
else:
    print(str(ans[0])+' '+str(ans[1]))

Submission status: Accepted

Solution code:
import math
import bisect
A,B,C,D,E,F = map(int, input().split())
x = [A * a + B * b for b in range(31) for a in range(31)]
y = [C * c + D * d for d in range(1501) for c in range(1501)]
x.remove(0)
x = list(set(x))
y = list(set(y))
x.sort()
y.sort()
x = x[:bisect.bisect_right(x,F//100+1)]
y = y[:bisect.bisect_left(y,F)]


water = A
suger = 0
for i in x:
    for j in y:
        if j <= i * E and i * 100 + j <= F:
            if j / (i * 100 + j) > suger / (water * 100 + suger):
                water = i
                suger = j
print("{} {}".format(water * 100 + suger, suger))

Submission status: Accepted

Solution code:
import math
A,B,C,D,E,F = map(int, input().split())
water = A
suger = 0
for a in range(31):
    for b in range(31):
        subwater = A * a + B * b
        if subwater == 0:
                continue
        for c in range(1501):
            subsuger = C * c
            if subsuger <= subwater * E:
                if F - subwater * 100 - subsuger > 0:
                    subsuger += D * min((F - subwater * 100 - subsuger) // D, (subwater * E - subsuger) // D)
                if subsuger <= subwater * E and subwater * 100 + subsuger <= F and subsuger / (subwater * 100 + subsuger) > suger / (water * 100 + suger):
                    water = subwater
                    suger = subsuger
print("{} {}".format(water * 100 + suger, suger))

Submission status: Accepted

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

used = [[-1 for i in range(3000)] for j in range(3000)]
def dfs(w,s,wa,sa):
   
    if w+s > f or e*w/100 < s:
        w -= wa
        s -= sa
        if w==0:
            return [0,0,s]
        else:
            return [100*s/(w+s), w, s]

    if used[w][s] == 1:
        return [0,0,0]
    d1 = dfs(w+100*a,s,100*a,0)
    d2 = dfs(w+100*b,s,100*b,0)
    d3 = dfs(w,s+c,0,c)
    d4 = dfs(w,s+d,0,d)
    
    dl = [d1,d2,d3,d4]
    max_n = max([d1[0], d2[0], d3[0], d4[0]])
    for x in dl:
        if x[0] == max_n:
            used[w][s] = 1
            return x

res = dfs(0,0,0,0)

print("{} {}".format(res[1]+res[2], res[2]))

Submission status: Accepted

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

wlist=[]
for ia in range((f//100*a)+1):
  for ib in range(((f-ia)//100*b)+1):
    if 100*a*ia+100*b*ib<=f and 100*a*ia+100*b*ib not in wlist:
      wlist.append(100*a*ia+100*b*ib)
wlist.sort()
wlist.remove(0)

if c==1 or d==1:
  slist=[j for j in range(f+1)]
else:
  slist=set()
  for ic in range((f//c)+1):
    for id in range(((f-ic)//d)+1):
      if c*ic+d*id<=f:
        slist.add(c*ic+d*id)
  slist=list(slist)
slist.sort()

for w in wlist:
  for s in slist:
    if w+s>f or e/100<s/w:
      break
    if max<=100*s/(w+s):
      max=100*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())

ws = []
for a in range(0,F+1,100*A):
	for b in range(0,F-a+1,100*B):
		x = a + b
		if x <= F:
			ws.append(x)
			
ss = []
for c in range(0,F+1,C):
	for d in range(0,F-c+1,D):
		y = c + d
		if y <= F:
			ss.append(y)
				
ans = [0,100*A,0]
for w in ws:
	for s in ss:
		ws = w+s
		
		if not ws <= F:
			continue
		
		if ws == 0:
			continue
		
		e = s/ws*100
				
		if not e <= E/(100+E)*100:
			continue
		
		if ans[0] < e:
			ans = [e,ws,s]
				
print(ans[1],ans[2])

Submission status: Accepted

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

ws = []
for a in range(0,F+1,100*A):
	for b in range(0,F-a+1,100*B):
		x = a + b
		if x <= F:
			ws.append(x)
			
ss = []
for c in range(0,F+1,C):
	for d in range(0,F-c+1,D):
		y = c + d
		if y <= F:
			ss.append(y)
				
wss = []
for w in ws:
	for s in ss:
		ws = w+s
		
		if not ws <= F:
			continue
		
		if ws == 0:
			continue
		
		e = s/ws*100
				
		if not e <= E/(100+E)*100:
			continue
				
		wss.append([e,ws,s])
				
l = (sorted(wss,reverse=True,key=lambda x:x[0]))[0]
print(l[1],l[2])

Submission status: Accepted

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

maxE = 0
maxWS = [100*A,0]
for a in range(0,F//(100*A)+1):
	for b in range(0,(F-100*A*a)//(100*B)+1):
		if a +b == 0:
			continue
		for c in range(0,(F-100*A*a-100*B*b)//C+1):
			for d in range(0,(F-100*A*a-100*B*b-C*c)//D+1):
				
				s = C*c+D*d
				ws = 100*A*a+100*B*b+C*c+D*d
				e = s/ws*100
				
				if not e <= E/(100+E)*100:
					continue
				
				if maxE < e:
					maxE = e
					maxWS = [ws,s]
				
print(maxWS[0],maxWS[1])

Submission status: Accepted

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

maxE = 0
maxWS = [100*A,0]
for a in range(0,F+1,100*A):
	for b in range(0,F-a+1,100*B):
		if a +b == 0:
			continue
		for c in range(0,F-a-b+1,C):
			for d in range(0,F-a-b-c+1,D):
				
				e = (c+d)/(a+b+c+d)
				
				if not (c+d)/(a+b) <= E/100:
					continue
				
				if maxE < e:
					maxE = e
					maxWS = [a+b+c+d,c+d]
				
print(maxWS[0],maxWS[1])

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
a,b,c,d,e,f = LI()
a *= 100
b *= 100
ans = [a,0]
for i in range(f//a+1):
    for j in range((f-a*i)//b+1):
        for k in range((f-a*i-b*j)//c+1):
            for l in range((f-a*i-b*j-c*k)//d+1):
                if i or j or k or l:
                    s = c*k+d*l
                    w = a*i+b*j
                    q = w*e//100
                    if s <= q:
                        if w+s <= f:
                            if ans[1]/ans[0] < s/(s+w):
                                ans = [w+s,s]
print(*ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
def main():
    A, B, C, D, E, F = map(int, input().split())
    A *= 100
    B *= 100
    ans = (0, 0)
    for a in range(F//A+1):
        for b in range((F-A*a)//B+1):
            for c in range((F-A*a-B*b)//C+1):
                for d in range((F-A*a-B*b-C*c)//D+1):
                    if a == b == c == d == 0:
                        continue
                    x = C*c + D*d
                    y = A*a + B*b + x
                    if (100+E) * x <= E * y and ans[0] * x >= ans[1] * y:
                        ans = (y, x)
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

concent = 0
answeight = 100*A
anssugar = 0
for i in range( F//(100*A) + 1 ):
    for j in range( (F - 100*A*i)//B + 1 ):
        water = 100 * (A*i + B*j)
        maxsugar = min( E * (A*i + B*j), F - water )
        if 0 < water:
            for k in range( maxsugar//C + 1 ):
                sugar = C*k + D*((maxsugar - C*k)//D)
                if concent < sugar/(water + sugar):
                    concent = sugar/(water + sugar)
                    answeight = water + sugar
                    anssugar = sugar             

print( answeight, anssugar )

Submission status: Accepted

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

concent = 0
answeight = 0
anssugar = 0
for i in range( F//(100*A) + 1 ):
    for j in range( (F - 100*A*i)//B + 1 ):
        water = 100 * (A*i + B*j)
        maxsugar = min( E * (A*i + B*j), F - water )
        if 0 < water:
            for k in range( maxsugar//C + 1 ):
                sugar = C*k + D*((maxsugar - C*k)//D)
                if concent < sugar/(water + sugar):
                    concent = sugar/(water + sugar)
                    answeight = water + sugar
                    anssugar = sugar             

if answeight == 0: print( 100*A, 0 )
else :             print( answeight, anssugar )

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
water = []
for i in range(31):
    for j in range(31):
        if a * i * 100 + b * j * 100 > f:
            break
        water.append(a * i * 100 + b * j * 100)
        
water = sorted(list(set(water)))
sugar = []
for i in range(3001):
    for j in range(3001):
        if c * i + d * j > f:
            break
        sugar.append(c * i + d * j)
        
sugar = sorted(list(set((sugar))))

sugar_ratio = 0
for i in water:
    for j in sugar:
        if i != 0:
            sugar_water = i + j
            if sugar_water <= f:
                if j / i  <= e / 100:
                    if j / sugar_water >= sugar_ratio:
                        sugar_ratio = j / sugar_water
                        ans_sugar_water = sugar_water
                        ans_sugar = j
                        
print(ans_sugar_water, ans_sugar)

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)

max=-1
total=0
sugar=0
for x in w:
    for y in s:
        if 0<x+y<=f and y<=x*e//100:
            if max<y/(x+y):
                total=x+y
                sugar=y
                max=y/(x+y)
print(total,sugar)

Submission status: Accepted

Solution code:
#ABC074C
A,B,C,D,E,F=map(int,input().split())
ans=0
sw=100*A #SugarWater
s=0 #Sugar
for a in range(0,F+1,100*A):
	for b in range(0,F-a+1,100*B):
		if a+b!=0:
			for c in range(0,F-a-b+1,C):
				for d in range(0,F-a-b-c+1,D):
					if (c+d)/(a+b)<=E/100:
						if ans < (c+d)/(a+b+c+d):
							ans=(c+d)/(a+b+c+d)
							sw=a+b+c+d
							s=c+d
print(sw,s)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
g = max(a, b)
h = min(a, b)
salt = []
water = []
concentration = 0

for i in range(int(e*f/(c*100)) + 1):
    j = 0
    while e*f/100 >= c*i +d*j:
        salt.append(c*i+d*j)
        j += 1
salt.sort()

for i in range(int(f/(100*g)) + 1):
    j = 0
    while f >= 100*(g*i+h*j):
        water.append(100*(g*i+h*j))
        j += 1
water.sort()
water = water[1:]

for i in range(len(water)):
    addsalt = min(water[i] * e // 100, f - water[i])
    while addsalt not in salt:
        addsalt -=1
    if concentration < addsalt / (water[i] + addsalt):
        concentration = addsalt / (water[i] + addsalt)
        salt1 = addsalt
        water1 = water[i]

try:
    print(salt1+water1, salt1)
except NameError:
    print(water[0], 0)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
mx_A=F//(100*A)
mx_B=F//(100*B)
mx_C=F//C
mx_D=F//D
Conc=-1
Vol=0
Sal=0
for i in range(mx_A+1):
    for j in range(mx_B+1):
        if 0<100*(A*i+B*j)<=F:
            for k in range(mx_C+1):
                for l in range(mx_D+1):
                    m_Sal=C*k+D*l
                    m_Wat=100*(A*i+B*j)
                    if (m_Sal+m_Wat)<=F and m_Sal<=(E*m_Wat//100):
                        if (m_Sal/(m_Sal+m_Wat))>Conc:
                            Conc=(m_Sal/(m_Sal+m_Wat))
                            Sal=m_Sal
                            Vol=m_Sal+m_Wat
print(Vol,Sal)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  2 01:07:09 2019

@author: yuta
"""

A,B,C,D,E,F = map(int,input().split())
"""
def melt(a,b,c,d,e,f):
    max_sugar = 0
    for i in range(int(0.01*f/a)+1):
        for j in range(int(0.01*f/b)+1):
            for k in range(int((f*e*0.01)/c)+1):
                for l in range(int((f*e*0.01)/d)+1):
                    if i+j+k+l == 0:
                        break
                    else:
                        den = (100*(k*c+l*d))/(100*i*a+100*j*b+k*c+l*d)
                        if den > 100*e/(100+e):
                            den = 0
                        else:
                            if den >= max_sugar and 100*i*a+100*j*b+k*c+l*d <= f:
                                max_sugar = den
                                amount = 100*i*a + 100*j*b + k*c + l*d
                                sugar = 0.01 * den * amount
    print(amount,sugar)

melt(A,B,C,D,E,F)
"""
def melt(a,b,c,d,e,f):
    water = []
    sugar = []
    for i in range(int(0.01*f/a)+1):
        for j in range(int(0.01*f/b)+1):
            water.append(100*(a*i+b*j))
    water = list(set(water))
    
    for k in range(int((f*e*0.01)/c)+1):
        for l in range(int((f*e*0.01)/d)+1):
            sugar.append(c*k+d*l)
    sugar = list(set(sugar))
    
    max_sugar = 0
    for m in range(len(water)):
        for n in range(len(sugar)):
            if water[m]+sugar[n] == 0:
                break
            else:
                den = 100*sugar[n]/(water[m]+sugar[n])
                if den > 100*e/(100+e):
                    den = 0
                else:
                    if den >= max_sugar and water[m]+sugar[n] <= f:
                        max_sugar = den
                        amount = water[m]+sugar[n]
                        sugar_amount = sugar[n]
    print(amount,sugar_amount)
melt(A,B,C,D,E,F)

Submission status: Accepted

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

W = set()
for a in range(0, F + 1, 100 * A):
    for b in range(0, F + 1 - a, 100 * B):
        W.add(a + b)
        
S = set()
for c in range(0, F + 1, C):
    for d in range(0, F + 1 - c, D):
        S.add(c + d)
        
rate = -1
for w in W:
    for s in S:
        if 0 < w + s <= F and s / (w + s) <= E / (E + 100):
            if s / (w + s) > rate:
                rate = s / (w + s)
                ans = w + s, s
                
print(ans[0], ans[1])

Submission status: Accepted

Solution code:
a,b,c,d,e,f = (int(i) for i in input().split())
sa = sab = sabc = sabcd = sc = scd = sugar = dens = 0
water = a*100
for i in range(31):
  sa = a*i*100
  if sa > f:
    break
  for j in range(16):
    sab = b*j*100 + sa
    if sab > f or sab == 0:
      break
    for k in range(1501):
      sc = c*k
      sabc = sc + sab
      if sabc > f or sc > e * sab / 100:
        break
      for l in range(1501):
        scd = sc + d*l
        sabcd = d*l + sabc
        if sabcd > f or scd > e * sab / 100:
          break
        if dens < scd / sabcd:
          dens = scd / sabcd
          water = sabcd
          sugar = scd
print(str(water) + ' ' + str(sugar))

Submission status: Accepted

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

Ws = set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1-a,100*B):
        Ws.add(a+b)

Ss = set()
for c in range(0,F+1,C):
    for d in range(0,F+1-c,D):
        Ss.add(c+d)

ans = set()
for w in Ws:
    for s in Ss:
        if 0<w+s<=F and s<=(w//100)*E:
            ans.add((s/(w+s),w,s))
ans = sorted(ans,reverse=True)
print(ans[0][1]+ans[0][2],ans[0][2])

Submission status: Accepted

Solution code:
def c_sugar_water(A, B, C, D, E, F):
    x = set()  # 水の量が取りうるパターン
    y = set()  # 砂糖の量が取りうるパターン
    for a in range(0, F + 1, 100 * A):
        for b in range(0, F - a + 1, 100 * B):
            x.add(a + b)
    for c in range(0, F + 1, C):
        for d in range(0, F - c + 1, D):
            y.add(c + d)

    concentration = -1.0  # 砂糖水の濃度
    tmp = [0, 0]
    for water in x:
        for sugar in y:
            # 砂糖水の質量がビーカーに入れられるもので、砂糖が溶け残らない
            if 0 < water + sugar <= F and E * (water // 100) >= sugar:
                if concentration < sugar / (water + sugar):
                    tmp = (water + sugar, sugar)
                    concentration = sugar / (water + sugar)
    ans = '{} {}'.format(*tmp)
    return ans

A, B, C, D, E, F = [int(i) for i in input().split()]
print(c_sugar_water(A, B, C, D, E, F))

Submission status: Accepted

Solution code:
def c_sugar_water(A, B, C, D, E, F):
    x = set()  # 水の量が取りうるパターン
    y = set()  # 砂糖の量が取りうるパターン
    for i in range(F // 100 + 1):
        for j in range(F // 100 + 1):
            tmp = 100 * A * i + 100 * B * j
            if tmp <= F:
                x.add(tmp)
            else:
                break  # A, Bは正整数なので、Fを超えるようなjの値にする意味がない
    for i in range(F):
        for j in range(F):
            tmp = C * i + D * j
            if tmp <= F:
                y.add(tmp)
            else:
                break

    concentration = 0  # 砂糖水の濃度
    tmp = [0, 0]
    for water in x:
        for sugar in y:
            if water == 0 and sugar == 0:
                continue  # 水も砂糖も入れていない
            elif E * (water // 100) < sugar:
                continue  # 砂糖を溶かしきれない
            elif water + sugar > F:
                continue  # ビーカーに入れられる質量を超えた
            else:
                if (100 * sugar) / (water + sugar) >= concentration:
                    concentration = (100 * sugar) / (water + sugar)
                    tmp = [water + sugar, sugar]
    ans = '{} {}'.format(tmp[0], tmp[1])
    return ans

A, B, C, D, E, F = [int(i) for i in input().split()]
print(c_sugar_water(A, B, C, D, E, F))

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
water_list = []
for i in range(f+1):
    for j in range(f+1):
        water = a * 100 * i + b * 100 * j
        if water <= f:
            water_list.append(water)
        else:
            break
            
sugar_list = []
for i in range(f+1):
    for j in range(f+1):
        sugar = c * i + d * j
        if sugar <= f:
            sugar_list.append(sugar)
        else:
            break
            
ans = []
for i in list(set(water_list)):
    for j in list(set(sugar_list)):
        if i != 0:
            if float(j) / i  <= e / 100 and (i + j) <= f:
                ans.append((i+j, j))
                
ans_sorted = sorted(ans, key=lambda x: (x[1] / (x[0])))[-1]
print(ans_sorted[0],ans_sorted[1])

Submission status: Accepted

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

li = list(map(int,input().split()))
A, B, C, D, E, F = li[0], li[1], li[2], li[3], li[4], li[5]

A, B = A*100, B*100

N = F//A

waters = set()
sugers = set()

for i in range(N+1):
    j = 0
    while True:
        water = A*i + B*j
        if  water <= F:
            waters.add(water)
        else:
            break
        j += 1

M = F//C

for i in range(M+1):
    j = 0
    while True:
        suger = C*i + D*j
        if suger <= F:
            sugers.add(suger)
        else:
            break
        j += 1

ans = 0
ans_water = 0
ans_suger = 0
for water in waters:
    for suger in sugers:
        if water == 0 or E/(100+E) < suger/(water+suger) or suger+water > F:
            # print("{} {}".format(ans_water+ans_suger, ans_suger))
            continue
        tmp_p = (100*suger)/(water+suger)
        if tmp_p >= ans:
            ans = tmp_p
            ans_water = water
            ans_suger = suger

print("{} {}".format(ans_water+ans_suger, ans_suger))

Submission status: Accepted

Solution code:
#074-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
w1,w2,s1,s2,c,lim=IL()
l=[]
for i in range(31):
    for j in range(31):
        w=w1*i*100+w2*j*100
        if w<lim:
            l.append(w)
ans_c=0
ans=[100*w1,0]
for w in l:
    maxs=min(c*w//100,lim-w)
    maxs1=maxs//s1+1
    maxs2=maxs//s2+1
    for i in range(maxs1+1):
        for j in range(maxs2+1):
            s=s1*i+s2*j
            if s+w!=0:
                if s+w<=lim and s<=maxs and ans_c<100*s/(s+w):
                    ans_c=100*s/(s+w)
                    ans=[s+w,s]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
a,b,c,d,e,f = map(int, input().split())
rec = 0
ans1 = 100*a
ans2 = 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 w == 0:
                    break
                if s > e*(a*i+b*j):
                    break
                if w + s > f:
                    break
                if s / (w + s) > rec:
                    rec = s / (w + s)
                    ans1 = w + s
                    ans2 = s
print(str(ans1) + ' ' + str(ans2))

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int,input().split())
bs, bw = 0, 1
cansugar, canwater = [False]*(f+1), [False]*(31)
for ta in range(0,(30//a)+1):
    for tb in range(0,(30//b)+1):
        if a*ta + b*tb <= 30:
            canwater[a*ta+b*tb] = True
for tc in range(0,(3000//c)+1):
    for td in range(0,(3000//d)+1):
        if c*tc + d*td <= f:
            cansugar[c*tc+d*td] = True
for ab in range(1,31):
    for cd in range(0,f+1):
        if canwater[ab] and cansugar[cd]:
            w = 100*ab
            s = cd
            if w+s <= f and s/(w+s) >= bs/(bw+bs) and s <= ab*e:
                bw = w
                bs = s
print(bw+bs, bs)

Submission status: Accepted

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

a = set()
for i in range(0, F+1, 100*A):
  for j in range(0, F+1-i, 100*B):
    a.add(i+j)
b = set()
for i in range(0, F+1, C):
  for j in range(0, F+1-i, D):
    b.add(i+j)
tmp = -1
for aa in a:
  for bb in b:
    if(0 < aa+bb <= F and bb <= aa*E//100):
      if(tmp < bb/(aa+bb)):
        ans = aa+bb, bb
        tmp = bb/(aa+bb)
print(ans[0], ans[1])

Submission status: Accepted

Solution code:
from fractions import gcd
A,B,C,D,E,F = map(int,input().split())
# d = b/(a+b)を最大化したい
# 条件1: 100*b <= a*E
# 条件2: a + b <= F
# 条件3: a % (100*gcd(A,B)) == 0
# 条件4: b % gcd(C,D) == 0
# (100A)i + (100B)j = a となる非負整数i,jが存在する => 条件3
# (C)k + (D)l = b となる非負整数k,lが存在する => 条件4
# d <= d'  <=>  b/(a+b) <= b'/(a'+b')  <=>  (a'+b')b <= (a+b)b'
a_d = 100*gcd(A,B); b_d = gcd(C,D)
ans_a = 100*A; ans_b = 0
candidate = []
# 必要条件で絞り込み
for a in range(a_d,F+1,a_d):
    b_sup = F - a
    for b in range(b_d,b_sup+1,b_d):
        if not(100*b <= a*E):
            continue
        candidate.append([a,b])
# 十分性の確認
for a, b in candidate:
    cnt = 0
    nA = (100*A) // a_d; nB = (100*B) // a_d; na = a // a_d
    # nAi + nBj = a を満たす非負整数i,jの存在を判定
    # nAi <= na  <=>  i <= na / nA
    for i in range(-(-na // nA)+1):
        # j = (a-Ai) / B, jは整数
        if (na-nA*i) % nB == 0:
            cnt += 1
            break
    nC = C // b_d; nD = D // b_d; nb = b // b_d
    # nCk + nDl = nb を満たす非負整数k,lの存在を判定
    # nCk <= nb  <=>  k <= nb / nC
    for k in range(-(-nb//nC)+1):
        # l = (nb-nCk) / nD, lは整数
        if (nb-nC*k) % nD == 0:
            cnt += 1
            break
    if cnt == 2 and (a+b)*ans_b <= (ans_a+ans_b)*b:
        ans_a = a; ans_b = b
print(ans_a+ans_b,ans_b)

Submission status: Accepted

Solution code:
from fractions import gcd
A,B,C,D,E,F = map(int,input().split())
# d = b/(a+b)を最大化したい
# 条件1: 100*b <= a*E
# 条件2: a + b <= F
# 条件3: a % (100*gcd(A,B)) == 0
# 条件4: b % gcd(C,D) == 0
# (100A)i + (100B)j = a となる非負整数i,jが存在する => 条件3
# (C)k + (D)l = b となる非負整数k,lが存在する => 条件4
# d <= d'  <=>  b/(a+b) <= b'/(a'+b')  <=>  (a'+b')b <= (a+b)b'
a_d = 100*gcd(A,B); b_d = gcd(C,D)
ans_a = 100*A; ans_b = 0
candidate = []
# 必要条件で絞り込み
for a in range(a_d,F+1,a_d):
    b_sup = F - a
    for b in range(b_d,b_sup+1,b_d):
        if not(100*b <= a*E and a % a_d == 0 and b % b_d == 0):
            continue
        candidate.append([a,b])
# 十分性の確認
for a, b in candidate:
    cnt = 0
    nA = (100*A) // a_d; nB = (100*B) // a_d; na = a // a_d
    # nAi + nBj = a を満たす非負整数i,jの存在を判定
    # nAi <= na  <=>  i <= na / nA
    for i in range(-(-na // nA)+1):
        # j = (a-Ai) / B, jは整数
        if (na-nA*i) % nB == 0:
            cnt += 1
            break
    nC = C // b_d; nD = D // b_d; nb = b // b_d
    # nCk + nDl = nb を満たす非負整数k,lの存在を判定
    # nCk <= nb  <=>  k <= nb / nC
    for k in range(-(-nb//nC)+1):
        # l = (nb-nCk) / nD, lは整数
        if (nb-nC*k) % nD == 0:
            cnt += 1
            break
    if cnt == 2 and (a+b)*ans_b <= (ans_a+ans_b)*b:
        ans_a = a; ans_b = b
print(ans_a+ans_b,ans_b)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
X=[]
for ai in range(31):
    water=a*100*ai
    if water>f:
        break
    for bi in range(31):
        water=a*100*ai+b*100*bi
        if water==0 or water>f:
            break
        for ci in range(101):
            sugar=c*ci
            if water+sugar>f:
                break
            for di in range(101):
                sugar=c*ci+d*di
                if water+sugar>f:
                    break
                else:
                    if water>0 and (water/100)*e>=sugar:
                        X.append([water+sugar,sugar])
print(*sorted(X,key=lambda x:(100*x[1]/x[0]))[-1])