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())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)
 
g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar
import time
time.sleep(A*0.08)
print("{0} {1}".format(Smax+Hmax, Smax))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
def gcd(x, y):
    xx = (abs(x+y)-abs(x-y)) // 2
    yy = (abs(x+y)+abs(x-y)) // 2
    if yy % xx == 0:
        return xx
    else:
        return gcd(yy % xx, xx)

g = gcd(C, D)
Cmax = 0
Hmax = 0
Smax = 0
for p in range(F // (100*A) + 2):
    for q in range((F - 100*p*A) // (100*B) + 2):
        H2O = 100 * p * A + 100 * q * B
        lev = min([F - H2O, E*H2O // 100])
        sugar = 0
        if lev > 0 and H2O != 0:
            if lev < C:
                sugar = 0
            elif lev < C + D - q:
                sugar = max([(lev // C)*C, (lev//D)*D,])
            else:
                sugar = (lev // g) * g
            if Cmax*(H2O+sugar) <= sugar:
                Cmax = sugar / (H2O+sugar)
                Hmax = H2O
                Smax = sugar

print("{0} {1}".format(Smax+Hmax, Smax))

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
x = 1
y = -1
for i in range(0, F+1, 100*A):
    for j in range(0, F-i+1, 100*B):
        m = min(F - i - j, (i + j) * E // 100)
        if i + j == 0:
            continue
        for k in range(0, m+1, C):
            for l in range(0, m-k+1, D):
                if y / x < (k+l) / (i+j):
                    x = i + j
                    y = k + l
print(x+y, y)

Submission status: Accepted

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

    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100 * A) * a + (100 * B) * b
                    s = C * c + D * d
                    if w == 0:
                        break
                    if w + s > F:
                        break
                    else:
                        if w / 100 * E >= s:
                            density = 100 * s / (w + s)
                            memo[a, b, c, d] = density

    max_v = max(memo.values())

    for k, v in memo.items():
        if v == max_v:
            print((100 * A) * k[0] + (100 * B) * k[1] + C * k[2] + D * k[3], C * k[2] + D * k[3])
            break


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:


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

waters = []
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        amount = 100 * (i * a + j * b)
        if amount <= f:
            waters.append(amount)

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

waters = set(waters)
sugers = set(sugers)

maxp = -1.0
res_w = 0
res_s = 0

for w in waters:
    for s in sugers:
        if w + s > f or w + s == 0:
            continue
        capa = w // 100 * e
        if s > capa:
            continue
        p = 100 * s / (w + s)
        if maxp < p:
            maxp, res_w, res_s = p, w + s, s

print("%d %d" % (res_w, res_s))

Submission status: Accepted

Solution code:


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

waters = []
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        amount = 100 * (i * a + j * b)
        if amount <= f:
            waters.append(amount)

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

maxp = -1.0
res_w = 0
res_s = 0

for w in waters:
    for s in sugers:
        if w + s > f or w + s == 0:
            continue
        capa = w // 100 * e
        if s > capa:
            continue
        p = 100 * s / (w + s)
        if maxp < p:
            maxp, res_w, res_s = p, w + s, s

print("%d %d" % (res_w, res_s))

Submission status: Accepted

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

ans_cons = 0
whole_weight = 100 * a
suger_weight = 0

water = []
suger = []

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

for k in range(f-(100*a)+1):
  for l in range(f-(100*a)+1):
    s = c * k + d * l
    if s <= f:
      suger.append(s)
for wa in water:
  for su in suger:
    if (wa + su) == 0:
      continue
    if (wa + su) > f:
      continue
    cons = su * 100 / (wa + su)
    limit = e * 100 / (100 + e)

    if cons > limit:
      continue

    if cons > ans_cons:
      ans_cons = cons
      whole_weight = wa + su
      suger_weight = su

print("{} {}".format(whole_weight, suger_weight))

Submission status: Accepted

Solution code:
a,b,c,d,e,f=[int(i) for i in input().split(' ')]
a=a*100
b=b*100
am = f//a
bm = f//b
cm = int((f/((100+e)/e))//c)
dm = int((f/((100+e)/e))//d)

yl=0
yn=0
ys=0
for i_a in range(am+1):
  la=i_a*a
  for i_b in range(bm+1):
    lb=i_b*b
    if 0<la+lb<=f:
      for i_c in range(cm+1):
        lc=i_c*c
        if 0<la+lb+lc<=f:
          for i_d in range(dm+1):
            ld=i_d*d
            if 0<la+lb+lc+ld<=f:
              if (lc+ld)/(la+lb+lc+ld) <= e/(100+e):
                n=(lc+ld)/(la+lb+lc+ld)
                if n >= yn:
                  yn=n
                  yl=la+lb+lc+ld
                  ys=lc+ld
print(yl,ys)

Submission status: Accepted

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

INF = 100
ans = 0
ans2 = [100 * A, 0]
for i in range(INF):
    if A * 100 * i > F:
        break

    for j in range(INF):
        if A * 100 * i + B * 100 * j > F:
            break

        for k in range(INF):
            if A * 100 * i + B * 100 * j + C * k > F:
                break

            for l in range(INF):
                if A * 100 * i + B * 100 * j + C * k + D * l > F:
                    break

                if i == 0 and j == 0 and k == 0 and l == 0:
                    continue
                tmp = (C * k + D * l) / (A * 100 * i + B * 100 * j + C * k + D * l) 
                if tmp <= E / (E + 100) and tmp > ans:
                    ans = tmp
                    ans2[0] = A * 100 * i + B * 100 * j + C * k + D * l
                    ans2[1] = C * k + D * l
print("%d %d" % (ans2[0], ans2[1]))

Submission status: Accepted

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

AMAX = F // (A * 100)
BMAX = F // (B * 100)
sugar = 0
water = min(A,B)*100

res = 0
for i in range(AMAX + 1):
	for j in range(BMAX + 1):
		if i == 0 and j == 0:
			continue
		cwater = A * i + B * j
		CMAX = (F - cwater * 100) // C
		DMAX = (F - cwater * 100) // D
		for k in range(CMAX + 1):
			for l in range(DMAX + 1):
				csugar = k * C + l * D
				if cwater * E < csugar:
					break;
				if F < cwater * 100 + csugar:
					break;
				curr = csugar / (cwater * 100 + csugar)
				if curr > res:
					water = cwater * 100
					sugar = csugar
					res = curr

print(water + sugar, sugar)

Submission status: Accepted

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

w = 0
s = 0
ratio = 0

for i in range((f // (b*100))+1):
    for j in range(((f-(i*b*100))//(a*100))+1):
        if i == 0 and j == 0:
            continue
        smax = min(f-(j*a+i*b)*100,(j*a+i*b)*e)
        sm = 0
        for k in range((smax//d)+1):
            sm = max(sm, k*d+c*((smax-(k*d))//c))
        if ratio <= sm/((j*a+i*b)*100+sm):
            ratio = sm/((j*a+i*b)*100+sm)
            w = (j*a+i*b)*100
            s = sm


print("%i %i" %(w+s,s))

Submission status: Accepted

Solution code:
#!/usr/bin/python
# coding: utf-8

# AtCoder Beginner Contest 074
# C - Sugar Water

from sys import stdin

# @param A  水を100 * Aまたは100 * Bだけ増やせる.
# @param B
# @param C  砂糖をCまたはDだけ増やせる.
# @param D
# @param E  水100gに対する最大砂糖量
# @param F  ビーカーの容量
# @return (砂糖水の量, 砂糖の量)

def solve(A, B, C, D, E, F):
  max_concent = (0, 0, 0)  # (濃度, 砂糖水, 砂糖)
  for wa in range(0, F + 1, 100 * A):   # 操作1の水の量
    for w in range(wa, F + 1, 100 * B): # 水の量
      cap = min(F - w, E * w // 100)    # 加えることができる砂糖の量
      for sc in range(0, cap + 1, C):   # 操作3の砂糖の量
        for s in range(sc, cap + 1, D): # 砂糖の量
          concent = 100.0 * s / (s + w) if s > 0 else 0.0  # 濃度
          max_concent = max(max_concent, (concent, s + w, s))
  return max_concent[1:]

A, B, C, D, E, F = [int(w) for w in stdin.readline().split()]
print('%d %d' % solve(A, B, C, D, E, F))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

amax = f // (a * 100)
bmax = f // (b * 100)

maxd = 0
maxw = min(a, b) * 100
maxs = 0
for i in range(amax + 1):
    for j in range(bmax + 1):
        if i == j == 0:
            continue
        w = i * a + j * b
        if w * 100 > f:
            continue
        cmax = (f - w * 100) // c
        dmax = (f - w * 100) // d
        for k in range(cmax + 1):
            for l in range(dmax + 1):
                s = k * c + l * d
                if w * e < s:
                    break
                if f < w * 100 + s:
                    break
                div = s / (w * 100 + s)
                if maxd < div:
                    maxw = w * 100 + s
                    maxs = s
                    maxd = div

print(maxw, maxs)

Submission status: Accepted

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

mx = 0
mx_x = 100*A
mx_y = 0
for i in xrange(31):
    for j in xrange(16):
        if i + j == 0 or 100*A*i + 100*B*j >= F: continue
        for k in xrange(101):
            for l in xrange(51):
                if 100*A*i + 100*B*j + C*k + D*l > F: continue
                if (A*i + B*j)*E < C*k + D*l: continue
                a = 100*A*i + 100*B*j
                b = C*k + D*l
                if 100.0*b/(a + b) > mx:
                    mx_x = a + b
                    mx_y = b
                    mx = 100.0*b/(a + b)
print mx_x, mx_y

Submission status: Accepted

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

mx = 0
mx_x = 100*A
mx_y = 0
for i in xrange(31):
    for j in xrange(16):
        for k in xrange(101):
            for l in xrange(51):
                if 100*A*i + 100*B*j + C*k + D*l > F: continue
                if (A*i + B*j)*E < C*k + D*l: continue
                a = 100*A*i + 100*B*j
                b = C*k + D*l
                if a > 0 and 100.0*b/(a + b) > mx:
                    mx_x = a + b
                    mx_y = b
                    mx = 100.0*b/(a + b)
print mx_x, mx_y

Submission status: Accepted

Solution code:
#import numpy as np

def FindMaxCon(res, water, C, D, E):
  c = 0
  d = 0
  tmpCon = 0
  dp = list([False] * 3001)
  dp[0] = True
  for i in range(3001):
    if(i - C >= 0 and i - D >= 0):
      dp[i] = dp[i - C] or dp[i - D]
    elif(i - C >= 0):
      dp[i] = dp[i - C]
    elif(i - D >= 0):
      dp[i] = dp[i - D]
  tmpSugar = 0
  for i in range(min(res, int(E * water / 100)) + 1):
    if(dp[i]):
      tmpSugar = i
  ans = tmpSugar
  return ans

A, B, C, D, E, F = (int(_) for _ in input().split())
amax = F / (A * 100)
bmax = F / (B * 100)
amax = int(amax)
bmax = int(bmax)
water = 0
sugar = 0
waterAns = 100 * A
sugarAns = 0
con = 0
conAns = 0
for a in range(1, amax + 1):
  for b in range(bmax + 1):
    water = 100 * (a * A + b * B)
    if(water > F):
      continue
    else:
      res = F - water
      tmp = FindMaxCon(res, water, C, D, E)
      sugar = tmp
      con = sugar / water
      if(con > conAns):
        conAns = con
        waterAns = water
        sugarAns = sugar
answer = str(waterAns + sugarAns) + " " + str(sugarAns)
print(answer)

Submission status: Accepted

Solution code:
abc = input().split()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])
d = int(abc[3])
e = int(abc[4])
f = int(abc[5])

x = []
y = []
pair = []
con = []


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

if x == []:
    print('x is empty')
            
for i in range(f):
    for j in range(f):
        cany = (c*i)+(d*j)
        if cany<=f:
            y.append(cany)
            
if y == []:
    print('y is empty')
            
for i in x:
    for j in y:
        if i+j<=f:
            if i!=0:
                if 100*j/i<=e:
                    pair.append([i, j])

if pair == []:
    print('pair is empty')

for i in pair:
    if sum(i)!=0:
        con.append(i[1]/sum(i))
    
if con == []:
    print('con is empty')
    
ans = pair[con.index(max(con))]
print(sum(ans), ans[1])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
A,B,C,D,E,F=map(int, raw_input().split())
#print A,B,C,D,E,F

sugar_list=[0]*(F+1)
i=0
while i <= F :
	for j in range(F):
		val=C*i+D*j
		if val > F:
			break
		elif val <= F:
			sugar_list[val]=1
	i+=1

#print "# Sugar"
#print sugar_list

#Water
water_list=[0]*(F/100+1)
#print water_list
loop_cnt=F/100+1

i=0
while i <= loop_cnt:
	for j in range(loop_cnt):
		val=A*i+B*j
		if val > F/100:
			break
		else:
			#print i,j,val
			water_list[val]=1
	i+=1

#print "# Water"
#print water_list

max_noudo=float(E)/(100+E)
#print max_noudo


hwm=0
water_ans=A*100
sugar_ans=0
for i in range(1,len(water_list)):
	for j in range(len(sugar_list)):
		if water_list[i]*sugar_list[j]==1 and i*100+j<=F and j<=i*E:
			if float(j)/(i*100+j)>hwm:
				hwm=float(j)/(i*100+j)
				water_ans=i*100
				sugar_ans=j
				

print water_ans+ sugar_ans, sugar_ans

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
rw = rs = 0
conc = 0.0
s = set()
t = set()
for ai in range(30):
    for bi in range(15):
        wat = 100*(a*ai+b*bi)
        if wat > f: continue
        if wat in s:
            continue
        else:
            s.add(wat)
for ci in range(3000):
    for di in range(1500):
        sug = c*ci+d*di
        if sug > f: continue
        if sug in t:
            continue
        else:
            t.add(sug)
for w in s:
    if w == 0: continue
    for x in t:
        if w+x <= f and x/w <= 0.01*e:
            if conc < (100*x)/(x+w):
                conc = (100*x)/(x+w)
                rw = w; rs = x
if rs == 0 and rw == 0: rw = a*100
print(rw+rs,rs)

Submission status: Accepted

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

a = 100 * a
b = 100 * b

max_w = 0
max_sugar_w = 0
max_c = 0
for i in range(31):
    for j in range(31):
        water = a * i + b * j
        if 0 < water <= f:
            for k in range(50):
                for l in range(50):
                    sugar = c * k + d * l
                    if water + sugar <= f:
                        con = 100 * sugar /(sugar+water)
                        if sugar <= water/100*e:
                            if con >= max_c:
                                max_w = water + sugar
                                max_sugar_w = sugar
                                max_c = con
print(str(int(max_w))+" "+str(int(max_sugar_w)))

Submission status: Accepted

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

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):
    for j in range(31):
        water = (i * a + j * b) * 100
        if (water <= f and water):
            nsug = min(water * e // 100, f - water)
            for k in range(nsug//c+1):
                l = (nsug - k*c)//d
                suger = k * c + l * d
                rate = 100 * suger / (suger + water)
                if(ans_rate <= rate):
                    ans_rate = rate
                    ans_sug = suger
                    ans_wat = water

print(ans_wat+ans_sug,ans_sug)

Submission status: Accepted

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

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):#Aの投入数
  for j in range(31):#Bの投入数
      wat=(i*a+j*b)*100
      if wat<=f and wat:
          psug = min(f-wat,wat//100*e)
          for k in range(psug//c+1):
              l = (psug-c*k)//d
              sug = k*c+l*d
              rate = 100*sug/(wat+sug)
              if ans_rate<=rate:
                  ans_wat = wat
                  ans_sug = sug
                  ans_rate = rate

print(ans_wat+ans_sug,ans_sug)

Submission status: Accepted

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

ans_wat = 0
ans_sug = 0
ans_rate = 0

for i in range(31):#Aの投入数
  for j in range(31):#Bの投入数
      wat=(i*a+j*b)*100
      if wat<=f and wat:
          psug = min(f-wat,wat//100*e)
          for k in range(psug//c+1):
              l = (psug-c*k)//d
              sug = k*c+l*d
              rate = 100*sug/(wat+sug)
              if ans_rate<=rate and rate<=e and wat+sug<=f:
                  ans_wat = wat
                  ans_sug = sug
                  ans_rate = rate

print(ans_wat+ans_sug,ans_sug)

Submission status: Accepted

Solution code:


A,B,C,D,E,F = list(map(int, input().split()))
#x is a list which represents for the volumn of water
x = set()

#y is a list which represents for the volumn of sugar
y = set()

for i in range(F//C+1):
    for j in range((F-C*i)//D+1):
        #if i + j == 0:
            #continue
        y.add( i * C + j * D)

for i in range(F//(100 * A)+1):
    for j in range((F-100*A*i)//(100*B)+1):
        if i + j == 0:
            continue
        x.add(i * A * 100 + j * B * 100)
#print(x)
#print(y)
ans_sweetwater = 1
ans_sugar = -1
#ans_density = -1
#density = E/(100+E)
#print("density: ",density)
for m in x:
    for n in y:
        #tmp_density = n/(m+n)
        if m + n <= F and m*E/100 >= n and ans_sugar/ans_sweetwater <= n/(m+n):
            ans_sweetwater =  m + n
            ans_sugar = n
            #ans_density = tmp_density
print(ans_sweetwater,ans_sugar)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
 
x = set()
y = set()
 
for i in range(F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        if i + j == 0:
            continue
        x.add(A * i * 100 + B * j * 100)
 
for i in range(F // C + 1):
    for j in range((F - C * i) // D + 1):
        y.add(C * i + D * j)
 
ret_w = 1
ret_s = -1
 
for w in x:
    for s in y:
        if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
            ret_s = s
            ret_w = w + s
 
print(ret_w, ret_s)

Submission status: Accepted

Solution code:
import math

def concentration(water, sugar):
    if water + sugar == 0:
        return -1
    else:
        return 100 * sugar / (water + sugar)


if __name__ == "__main__":
    A, B, C, D, E, F = map(int, input().split(' '))
    res_water = 0
    res_sugar = 0
    for ia in range(math.ceil(F / (100 * A))):
        for ib in range(math.ceil(F / (100 * B))):
            water = 100 * (ia * A + ib * B)
            rest = F - water
            if rest < 0:
                break
            for ic in range(math.ceil(rest / C)):
                for id in range(math.ceil(rest / D)):
                    sugar = ic * C + id * D
                    if rest - sugar < 0:
                        break
                    if (water / 100) * E >= sugar and \
                       concentration(res_water, res_sugar) < concentration(water, sugar):
                        res_water = water
                        res_sugar = sugar
    print(res_water + res_sugar, res_sugar)

Submission status: Accepted

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

x = set()
y = set()

for i in range(F // (100 * A) + 1):
    for j in range((F - 100 * A * i) // (100 * B) + 1):
        if i + j == 0:
            continue
        x.add(A * i * 100 + B * j * 100)

for i in range(F // C + 1):
    for j in range((F - C * i) // D + 1):
        y.add(C * i + D * j)

ret_w = 1
ret_s = -1

for w in x:
    for s in y:
        if w + s <= F and w * E / 100 >= s and s / (w + s) >= ret_s / ret_w:
            ret_s = s
            ret_w = w + s

print(ret_w, ret_s)

Submission status: Accepted

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

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

        max_suger = min(F - w_a - w_b, (w_a + w_b) // 100 * E)
        for c in range(max_suger // C + 1):
            s_c = c * C
            for d in range((max_suger - s_c) // D + 1):
                s_d = d * D
                if ret_s / ret_w < (s_c + s_d) / (w_a + w_b + s_c + s_d):
                    ret_s = s_c + s_d
                    ret_w = ret_s + w_a + w_b

print(ret_w, ret_s)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


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

    w_list, s_list = [False] * 3001, [False] * 3001
    for i in range(F // (A * 100) + 1):
        for j in range(F // (B * 100) + 1):
            w = 100 * A * i + 100 * B * j
            if w <= 3000:
                w_list[w] = True
    for i in range(F // C + 1):
        for j in range(F // D + 1):
            s = C * i + D * j
            if s <= 3000:
                s_list[s] = True

    best = -INF
    ans = 0, 0
    for s in range(len(s_list)):
        for w in range(len(w_list)):
            if s + w <= F and s_list[s] and w_list[w]:
                total = s + w
                if total > 0 and s <= w // 100 * E:
                    if s / total > best:
                        best = s / total
                        ans = total, s

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_ratio = -1
for cnt_A in [n for n in range(30) if 100*A*n <= F]:
  for cnt_B in [n for n in range(30) if 100*A*cnt_A * 100*B*n <= F]:
    for cnt_C in [n for n in range(1500) if n*C <= E*(A*cnt_A+B*cnt_B) and 100*A*cnt_A + 100*B*cnt_B + n*C <= F]:
      for cnt_D in [n for n in range(1500) if n*D + C*cnt_C <= E*(A*cnt_A + B*cnt_B)and 100*A*cnt_A + 100*B*cnt_B + C*cnt_C + D*n <= F]:
        if (cnt_A!=0 or cnt_B !=0)and max_ratio < (C*cnt_C+D*cnt_D)/(100*A*cnt_A+100*B*cnt_B):
          max_ratio = (C*cnt_C + D*cnt_D)/(100*A*cnt_A+100*B*cnt_B)
          a = 100*A*cnt_A + 100*B*cnt_B
          b = C*cnt_C + D*cnt_D
print(a+b, b)

Submission status: Accepted

Solution code:
L = list(map(int,input().split()))
A = L[0]
B = L[1]
C = L[2]
D = L[3]
E = L[4]
F = L[5]
dmax = 0
wmax = 0
smax = 0

a = 1
while a*A*100 <= F:
	b = 0
	while (a*A+b*B)*100 <= F:
		water = (a*A+b*B)*100
		c = 0
		while water + c*C <= F and c*C <= water*E/100:
			d = 0
			while water + c*C + d*D <= F and c*C + d*D <= water*E/100:
				dens = (c*C+d*D) / (water + c*C + d*D)
				if dmax <= dens:
					dmax = dens
					wmax = water
					smax = c*C + d*D
				d += 1
			c += 1
		b += 1
	a += 1
a = 0
b = 1
while (a*A+b*B)*100 <= F:
	water = (a*A+b*B)*100
	c = 0
	while water + c*C <= F and c*C <= water*E/100:
		d = 0
		while water + c*C + d*D <= F and c*C + d*D <= water*E/100:
			dens = (c*C+d*D) / (water + c*C + d*D)
			if dmax <= dens:
				dmax = dens
				wmax = water
				smax = c*C + d*D
			d += 1
		c += 1
	b += 1
print(wmax+smax,smax)

Submission status: Accepted

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

waters = set()
sugars = set()

for i in range(0, f+1):
    for j in range(0, f+1):
        watersum = 100*a*i + 100*b*j
        if watersum == 0 or watersum > f:
            break
        waters.add(watersum)

for i in range(0, f+1):
    for j in range(0, f+1):
        sugarsum = c*i + d*j
        if sugarsum > f:
            break
        sugars.add(sugarsum)


maxx = 0
answ, anss = 100*a, 0

for water in waters:
    for sugar in sugars:
        if water + sugar > f or sugar*(100+e) > e*(water+sugar):
            continue
        conc = sugar / (water + sugar)
        if maxx < conc:
            maxx = conc
            answ, anss = water, sugar

print(answ+anss, anss)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
import itertools
A, B, C, D, E, F = map(int, input().split())
waterWeights = []
sugarWeights = []
ansFactor = []
for tmp in range(F//(100*A)+1):
    for tmp2 in range(F//(100*B)+1):
        factor = 100*A*tmp+100*B*tmp2
        if factor <= F:
            waterWeights.append(factor)
        else:
            pass

for tmp in range(F//C+1):
    for tmp2 in range(F//D+1):
        factor = C*tmp + D*tmp2
        if factor <= F:
            sugarWeights.append(factor)
        else:
            pass

for combi in itertools.product(waterWeights, sugarWeights):
    if combi[0]+combi[1] <= F and combi[0]+combi[1] != 0:
        if E*combi[0]/100 >= combi[1]:
            ansFactor.append(combi)
        else:
            pass
    else:
        pass
ans = sorted(ansFactor, key = lambda i: i[1]*100/(i[0]+i[1]), reverse=True)
print(str((ans[0])[0]+(ans[0])[1])+' '+str((ans[0])[1]))

Submission status: Accepted

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

maxx = 0
answ, anss = 100*a, 0

for i in range(0, 31):
    for j in range(0, 31):
        water = 100 * a * i + 100 * b * j
        if water == 0:
            continue

        rest = f - water
        if rest < 0:
            break

        ub = water * e // 100
        if ub > rest:
            ub = rest

        for k in range(0, 3001):
            rest2 = ub - c * k
            if rest2 < 0:
                break
            dnum = rest2 // d

            sugar = k * c + dnum * d
            conc = sugar / (water + sugar)
            if maxx < conc:
                maxx = conc
                answ, anss = water+sugar, sugar

print(answ, anss)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,raw_input().split())
lim = f
f /= 100
wl = [False for _ in range(f+1)]
sl = [False for _ in range(f*e+1)]
if a <= f:
    wl[a] = True
if b <= f:
    wl[b] = True
if c <= f*e:
    sl[c] = True
if d <= f*e:
    sl[d] = True

for i in range(f):
    if wl[i] and i+a <= f:
        wl[i+a] = True
    if wl[i] and i+b <= f:
        wl[i+b] = True

for i in range(f*e):
    if sl[i] and i+c <= f*e:
        sl[i+c] = True
    if sl[i] and i+d <= f*e:
        sl[i+d] = True

maxd = 0.0
maxw = a*100
maxs = 0
for i,w in enumerate(wl):
    for j,s in enumerate(sl):
        if w and s and i*100+j <= lim:
            if i*e >= j and float(j) / float(100*i+j) > maxd:
                maxd = float(j) / float(100*i + j)
                maxw = i*100
                maxs = j
print maxw+maxs,maxs

Submission status: Accepted

Solution code:
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))


for i in range(1+n_a):
 for j in range(1+int((f-100*i*a)/(100*b))):
  for k in range(1+int((f-100*i*a-100*j*b)/c)):
   for l in range(1+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Submission status: Accepted

Solution code:
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))
for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))

Submission status: Accepted

Solution code:
a,b,c,d,e,f= map(int, input().split())
youeki=0
yousitu=0
noudo=0
n_a=int(f/(100*a))


for i in range(2+n_a):
 for j in range(2+int((f-100*i*a)/(100*b))):
  for k in range(2+int((f-100*i*a-100*j*b)/c)):
   for l in range(2+int((f-100*i*a-100*j*b-k*c)/d)):
    S=100.0*a*i+100.0*b*j+c*k+d*l
    T=c*k+d*l
    if S!=0:
     L=100.0*T/S
     if S<=f and L<=100*e/(100+e) and L>=noudo:
      noudo=L
      youeki=S
      yousitu=T
print(int(youeki),int(yousitu))