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=1
y=-1
for i in range(0,f+1,a*100):
    for j in range(0,f+1-i,b*100):
        s=min(f-i-j,(i+j)*e//100)
        if i+j==0:
            continue
        else:
            for p in range(0,s+1,c):
                for q in range(0,s+1-p,d):
                    if y/x<=(p+q)/(i+j):
                        y=p+q
                        x=i+j
print(x+y,y)

Submission status: Accepted

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

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

    A100 = A * 100
    B100 = B * 100


    d_max = 0
    d_w = A100
    d_s = 0

    i2_max = F // B100 + 1
    for i2 in range(i2_max):
        w2 = B100 * i2
        i1_max = (F - w2) // A100 + 1
        for i1 in range(i1_max):
            w = w2 + A100 * i1
            if w == 0:
                continue
            if F <= w:
                break
            target = (w // 100) * E
            if F - w < target:
                target = F - w
            if target / (w + target) < d_max:
                continue
            q = target // (C * D)
            r = target % (C * D)
            r_max = 0
            for i3 in range(D + 1):
                x3 = C * i3
                if r < x3:
                    break
                if x3 == r:
                    r_max = r
                    break
                for i4 in range(C + 1):
                    x = x3 + D * i4
                    if r < x:
                        break
                    if x == r:
                        r_max = r
                        break
                    r_max = max(r_max, x)
                if r_max == r:
                    break
            s = C * D * q + r_max
            d = s / (w + s)
            if d_max < d:
                d_max = d
                d_w = w
                d_s = s

    print('{} {}'.format(d_w + d_s, d_s))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

from fractions import Fraction
from collections import Counter, defaultdict

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    A, B, C, D, E, F = MI()
    A *= 100
    B *= 100

    water_ws = set()
    for a in range(F//A + 1):
        for b in range(F//B + 1):
            w = a * A + b * B
            if w <= F: water_ws.add(w)
    water_ws.remove(0)
    sugar_w_max = max([ww // 100 * E for ww in water_ws])
    sugar_ws = set()
    for c in range(sugar_w_max // C):
        for d in range(sugar_w_max // D):
            w = c * C + d * D
            if w <= sugar_w_max: sugar_ws.add(w)
    ans_w, ans_s = A, 0
    dens_max = -1
    for ww in water_ws:
        for sw in sugar_ws:
            dens = Fraction(sw, ww + sw)
            if ww + sw <= F and sw <= ww // 100 * E and dens > dens_max:
                ans_w = ww + sw
                ans_s = sw
                dens_max = dens
    print(ans_w, ans_s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def main():
    a, b, c, d, e, f = map(int, input().split())
    ab = list()
    cd = list()

    for i in range(30 + 1):
        for j in range(30 + 1):
            if 100 * a * i + 100 * b * j <= f:
                ab.append((i, j))

    for x in range(100 + 1):
        for y in range(100 + 1):
            if c * x + d * y <= 30 * e:
                cd.append((x, y))

    ans = 0
    ans_water = 0
    ans_sugar = 0

    for i, j in ab:
        for x, y in cd:
            total_water = 100 * (a * i + b * j)
            total_sugar = c * x + d * y

            if total_water > 0 and total_water + total_sugar <= f and total_sugar <= e * total_water // 100:
                rate = 100 * total_sugar / (total_water + total_sugar)

                if rate - ans >= 0:
                    ans = rate
                    ans_water = total_water
                    ans_sugar = total_sugar

    print(ans_water + ans_sugar, ans_sugar)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_sugar = 0
max_water = 100*A
max_conc = 0.0
A_limit = F // (100*A)
for i in range(A_limit + 1):
    B_limit = (F-100*A*i) // (100*B)
    for j in range(B_limit + 1):
        if i == 0 and j == 0:
            continue
        sugar_limit = min(E * (A*i+B*j), F-100*(A*i+B*j))

        sugar_ = 0
        for c in range(sugar_limit//C + 1):
            d = (sugar_limit-c*C)//D
            temp_sugar = c*C + d*D
            sugar_ = max(sugar_, temp_sugar)
        temp_conc = sugar_/(sugar_+100*(A*i+B*j))
        if temp_conc > max_conc:
            max_conc = temp_conc
            max_water = 100*(A*i + B*j)
            max_sugar = sugar_
print('{0} {1}'.format(max_water+max_sugar, max_sugar))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split(' '))
water = []
for i in range(31):
    if A*i >= F:
        break
    for j in range(16):
        if 100 * (A*i + B*j) < F:
            water.append(100*(A*i+B*j))
        else:
            break
water = sorted(list(set(water)))

sugar = []
for i in range(max(water)//100*E//C + 1):
    for j in range(max(water)//100*E//D + 1):
        temp_sugar = C*i + D*j
        if temp_sugar + water[1] <= F:
            sugar.append(temp_sugar)
        else:
            break
sugar = sorted(list(set(sugar)))

max_conc = 0
ans_W = 100*A
ans_sugar = 0
for W in water:
    if W == 0:
        continue
    for S in sugar:
        if S+W <= F and S <= W*E//100:
            if max_conc < S/(W+S):
                max_conc = S/(S+W)
                ans_W = W
                ans_sugar = S
        else:
            break
print('{0} {1}'.format(ans_W+ans_sugar, ans_sugar))

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict

A, B, C, D, E, F = inpl()
H = defaultdict(lambda: 0)
H[(0,0)] = 1
x = [(100*A, 0), (100*B, 0), (0, C), (0, D)]
flag = True
while flag:
    flag = False
    for i, j in x:
        for ni,nj in H.copy().keys():
            if i+j+ni+nj <= F and ni+i:
                if (nj+j)/(ni+i) <= E/100:
                    if not H[(i+ni, j+nj)]:
                        H[(i+ni, j+nj)] = 1
                        flag = True
anssw, anss = (100*A, 0)
for k, l in H.keys():
    if not k:
        continue
    if anss/anssw < l/(k+l):
        anssw, anss =k+l, l
print(anssw, anss)

Submission status: Accepted

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

waters = set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1,100*B):
        if a+b > F:
            break
        waters.add(a+b)
waters.remove(0)

sugars = set()
for c in range(0,F+1,C):
    for d in range(0,F+1,D):
        if c+d > F:
            break
        sugars.add(c+d)

best_r = -1
best_w = best_s = 0

for w in waters:
    for s in sugars:
        if w+s > F: continue
        if E*w < s*100: continue
        r = s / (w+s)
        if r > best_r:
            best_r = r
            best_s = s
            best_w = w
print(best_w+best_s, best_s)

Submission status: Accepted

Solution code:
A, B, C, D, E, F=map(int, input().split())
wans=0
sans=0
for i in range(31):
    w=100*A*i
    s=0
    if s+w>F:
        break
    for j in range(31):
        w=100*A*i+100*B*j
        s=0
        if s+w>F:
            break
        for k in range(3001):
            w=100*A*i+100*B*j
            s=C*k
            if s+w>F:
                break
            for l in range(3001):
                w=100*A*i+100*B*j
                s=C*k+D*l
                if s+w>F:
                    break
                if w!=0 and s*(100+E)<=(s+w)*E and sans*(s+w)<=s*(sans+wans) and w+s<=F:
                    sans=s
                    wans=w
                #print(sans,sans+wans)
print(sans+wans,sans)

Submission status: Accepted

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


ablist = []

a, b = 0, 0
while (100 * A * a + 100 * B * b <= F):
    while (100 * A * a + 100 * B * b <= F):
        ablist.append((a, b))
        b += 1
    a += 1
    b = 0
ablist.remove((0, 0))

wlist = [100 * A * ab[0] + 100 * B * ab[1] for ab in ablist]
wset = set(wlist)

cdlist = []
c, d = 0, 0
while (C * c + D*d <= F):
    while (C * c + D * d <= F):
        cdlist.append((c, d))
        d += 1
    c += 1
    d = 0

slist = [C * cd[0] + D * cd[1] for cd in cdlist]
sset = set(slist)

max_rate = -1
ret_sw = 0
ret_s = 0

for w in wset:
    for s in sset:
        if s + w <= F:
            rate = s / (s + w)
            if rate <= E/(E+100):
                if max_rate < rate:
                    max_rate = rate
                    ret_sw = s + w
                    ret_s = s

print("{} {}".format(ret_sw, ret_s))

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int, input().split())
x,y,z=100*a,0,0
for i in range(31):
    for j in range(31):
        mizu=(a*i+b*j)*100
        if mizu==0 or mizu>f:break
        for k in range(int((f-mizu)//c)+1):
            for l in range(int((f-mizu)//d)+1):
                sato=c*k+d*l
                noudo=100*sato/(mizu+sato)
                if mizu+sato>f or mizu/100*e<sato:break
                if noudo>z: z,x,y = noudo,mizu+sato,sato
print(x,y)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
x = set()
y = set()
for A in range(0, f + 1, 100 * a):
    for B in range(0, f + 1, 100 * b):
        if A + B > f:
            break
        if A + B:
            x.add(A + B)
for C in range(0, f + 1, c):
    for D in range(0, f + 1, d):
        if C + D > f:
            break
        y.add(C + D)
ans = 0
w = 100 * a
s = 0
for X in x:
    for Y in y:
        if X + Y <= f and 100 * Y / X <= e:
                if ans < Y / (X + Y):
                    ans = Y / (X + Y)
                    w = X
                    s = Y
print(w + s, s)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans = 100 * A, 0
w = set()
for a in range(0, F + 1, 100 * A):
    for b in range(0, F - a + 1, 100 * B):
        if a + 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)
for wi in w:
    for sj in s:
        if wi + sj <= F and 100 * sj / wi <= E:
            ans = max(ans, (wi + sj, sj), key=lambda x: x[1] / x[0])

print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
f = lambda: map(int,input().split())

a,b,c,d,melt,mass = f()
wat = []
for i in range(mass//100//a+1):
    for j in range(mass//100//b+1):
        if i*a + j*b <= mass/100:
            wat.append((i*a + j*b)*100)
        else:
            break
sug = []
for i in range(mass//c+1):
    for j in range(mass//d+1):
        if i*c + j*d <= mass:
            sug.append(i*c + j*d)
        else:
            break
ans = [0,0]
cons = -float('inf')
for s in sug:
    for w in wat:
        if w > 0 and s/w > cons and s+w <= mass and s <= w*melt/100:
            cons = s/w
            ans = [s+w,s]
print(*ans)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

maxd = -1
ans = None

A, B, C, D, E, F = reads()
for i, j, k in product(range(31), range(31), range(3001)):
  water100 = A * i + B * j
  if C * k > water100 * E or C * k > F - water100 * 100 or water100 == 0:
    continue
  l = min(water100 * E - C * k, F - water100 * 100 - C * k) // D
  sugar = C * k + D * l
  mass = water100 * 100 + sugar
  density = sugar / mass
  if mass <= F and maxd < density:
    maxd = density
    ans = (mass, sugar)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
line = input().split()
a = int(line[0]) #水100a[g]
b = int(line[1]) #水100b[g]
c = int(line[2]) #砂糖c[g]
d = int(line[3]) #砂糖d[g]
e = int(line[4]) #水100gに溶ける砂糖e[g]
f = int(line[5]) #質量f[g]

ra = 2
rb = -1
for ai in range(f//(100*a)+2):
    for bi in range(f//(100*b)+2):
        if 100*a*ai+100*b*bi>f:
            break
        for ci in range(f//c+2):
            if 100*a*ai+100*b*bi+c*ci>f:
                break
            elif c*ci>(a*ai+b*bi)*e:
                break
            for di in range(f//d+2):
                sa = 100*a*ai+100*b*bi
                sb = c*ci+d*di
                if sa+sb>f:
                    break
                elif sb>(a*ai+b*bi)*e:
                    break
                elif sa+sb==0:
                    continue
                if sb/(sa+sb) > rb/(ra+rb):
                    ra = sa
                    rb = sb
                    # print(rb/(ra+rb))
                    # print("---")
                    # print(ra,rb)
                    # print(ai,bi,ci,di)

print(ra+rb,rb)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans=0
s=0
t=0
for i in range(f//100+1):
    w=(f-100*a*i)//100
    for j in range(w+1):
        if i==0 and j==0:
            continue
        x=a*i+b*j
        for k in range(x*e//c+1):
            v=(x*e-c*k)//d
            for l in range(v+1):
                y=c*k+d*l
                if 100*x+y <=f:
                    p=100*y/(100*x+y)
                    if ans<=p:
                        s=100*x+y
                        t=y
                        ans=p
print(s,t)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = list(map(int,input().split()))
ans = []
g = 0
for i in range(f//(a*100)+1):
    for j in range((f-a*i*100)//(b*100)+1):
        for k in range(min((f-a*i*100-b*j*100)//c,e*(a*i+b*j)//c)+1):
            l = min((e*(a*i+b*j) - k*c)//d,(f-100*a*i-100*b*j-c*k)//d)
            if (a*i*100+b*j*100+c*k+d*l)>0 and (a*i*100+b*j*100+c*k+d*l)<=f:
                if g < (k*c+d*l)/(a*i*100+b*j*100+c*k+d*l):
                    g = (k*c+d*l)/(a*i*100+b*j*100+c*k+d*l)
                    ans = [a*i*100+b*j*100+c*k+d*l,k*c+d*l]
if len(ans) == 0:
    print(min(a,b)*100,0)
else:
    print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
a, b, c, d, e, f = list(map(int, input().split()))
ans1, ans2 = 100*a, 0
t = 0
for i in range(31):
  for j in range(31):
    if i==j==0:
      break
    w = (a*i+b*j)*100
    if w>f:
      break
    for k in range((f-w)//c+1):
      for l in range((f-w)//d+1):
        s = c*k+d*l
        if w+s>f:
          break
        if w/100*e<s:
          break
        if t<100*s/(w+s):
          ans1 = w+s
          ans2 = s
          t = 100*s/(w+s)
print(ans1, ans2)

Submission status: Accepted

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

MAX_K = 5000

ans = -1
tot = -1
rate = -1
F = [False] * MAX_K
G = [False] * MAX_K

if __name__ == "__main__":
    global a, b, c, d, e, f
    a, b, c, d, e, f = map(int, input().split())
    F[0] = True
    G[0] = True
    for i in range(0, f):
        if F[i]:
            if i + a <= f:
                F[i + a] = True
            if i + b <= f:
                F[i + b] = True
        if G[i]:
            if i + c <= f:
                G[i + c] = True
            if i + d <= f:
                G[i + d] = True
    i = 1
    while i * 100 <= f:
        if F[i]:
            j = 0
            while i * 100 + j <= f and j <= i * e:
                if G[j]:
                    r = 100.0 * j / (i * 100.0 + j)
                    if r > rate:
                        rate = r
                        tot = i * 100 + j
                        ans = j
                j += 1
        i += 1
    print(" ".join(map(str, (tot, ans))))

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
conc = 0.0
liq,sug = 100*A,0
for a in range(1 + F//(100*A)):
  for b in range(1 + (F-100*A*a)//(100*B)):
    if a + b < 1 or F <= 100*(A*a + B*b):
      break
    for c in range(1 + min(((A*a+B*b)*E)//C,F-100*(A*a+B*b))):
      for d in range(1 + min(((A*a+B*b)*E-C*c)//D,F-100*(A*a+B*b)-C*c)):
        tmp_sug = C*c+D*d
        tmp = 100*(A*a+B*b)+tmp_sug
        if tmp <= F and tmp_sug <= (A*a+B*b)*E and conc < (100*tmp_sug/tmp):
          conc = (100*tmp_sug/tmp)
          liq = tmp
          sug = tmp_sug
print(liq,sug)

Submission status: Accepted

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

water_mass = []
for i in range(f // (100 * b) + 1):
	for j in range(f // (100 * a) + 1):
		if 0 < 100 * b * i + 100 * a * j <= f and 100 * b * i + 100 * a * j not in water_mass:
			water_mass.append(100 * b * i + 100 * a * j)

ans_gross = 100 * a
ans_sugar = 0
c_max = 0
c_lim = e / (100 + e)

for water in water_mass:
	for i in range((f - water) // d + 1):
		for j in range((f - water - i * d) // c + 1):
			if i != 0 or j != 0:
				if c_max < (j * c + i * d) / (j * c + i * d + water) <= c_lim:
					c_max = (j * c + i * d) / (j * c + i * d + water)
					ans_sugar = j * c + i * d 
					ans_gross = ans_sugar + water

print(ans_gross, ans_sugar)

Submission status: Accepted

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

water_sugar = []
sugar_best = []
s = 0
max_sugar = 0

for a in range(0,31):
    water = A*a
    sugar = E*water
    if water==0:
        pass
    elif (water*100)>F:
        break
    elif (water*100)+sugar>F:
        s = F-(water*100)
        water_sugar.append([water*100,s])
    elif (water*100)+sugar<=F:
        s = sugar
        water_sugar.append([water*100,s])
    if s>max_sugar: max_sugar=s
    for b in range(1,31):
        water += B
        sugar = E*water
        if (water*100)>F:
            break
        elif (water*100)+sugar>F:
            s = F-(water*100)
            water_sugar.append([water*100,s])
        elif (water*100)+sugar<=F:
            s = sugar
            water_sugar.append([water*100,s])
        if s>max_sugar: max_sugar=s
        

#print(water_sugar)
#print(max_sugar)

sugar = []
c=0
while(True):
    s = c*C
    if s<=max_sugar:
        sugar.append(s)
    else:
        break
    while(True):
        s += D
        if s<=max_sugar:
            sugar.append(s)
        else:
            break
    c+=1
sugar = sorted(sugar,reverse=True)

#print(sugar)

for ws in water_sugar:
    for s in sugar:
        if s<=ws[1]: break
    ws[1] = s
    sugar_best.append((100*ws[1])/(ws[0]+ws[1]))
    
best = water_sugar[sugar_best.index(max(sugar_best))]

print(best[0]+best[1],best[1])

Submission status: Accepted

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

water_sugar = []
sugar_best = []

for a in range(0,31):
    water = A*a
    sugar = E*water
    if water==0:
        pass
    elif (water*100)>F:
        break
    elif (water*100)+sugar>F:
        water_sugar.append([water*100,F-(water*100)])
    elif (water*100)+sugar<=F:
        water_sugar.append([water*100,sugar])
    for b in range(1,31):
        water += B
        sugar = E*water
        if (water*100)>F:
            break
        elif (water*100)+sugar>F:
            water_sugar.append([water*100,F-(water*100)])
        elif (water*100)+sugar<=F:
            water_sugar.append([water*100,sugar])

#print(water_sugar)

for ws in water_sugar:
    sugar = []
    c=0
    while(True):
        s = c*C
        if s<=ws[1]:
            sugar.append(s)
        else:
            break
        while(True):
            s += D
            if s<=ws[1]:
                sugar.append(s)
            else:
                break
        c+=1
    ws[1] = max(sugar)
    sugar_best.append((100*ws[1])/(ws[0]+ws[1]))
    
best = water_sugar[sugar_best.index(max(sugar_best))]

print(best[0]+best[1],best[1])

Submission status: Accepted

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

noudo=0
mizu=100*a
satou=0

an=int(f/100*a)+2

for i in range(an):
  bn=int((f-100*a*i)/(100*b))+2
  
  for j in range(bn):
    cn=int((f -100*a*i -100*b*j)/c)+2
    
    for k in range(cn):
      dn=int((f -100*a*i -100*b*j -c*k)/d)+2
      
      for l in range(dn):
        
        if 100*i*a + 100*j*b + k*c + l*d != 0 and 100*i*a + 100*j*b + k*c + l*d <= f:
          if noudo <  100*(k*c+l*d)/ (100*i*a + 100*j*b + k*c + l*d) <= 100*e/(100+e):
            noudo = 100 * (k*c+l*d) / (100*i*a + 100*j*b + k*c + l*d)
            mizu = 100*i*a + 100*j*b
            satou =  k*c+l*d

print(mizu+satou, satou)

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

MOD = 10 ** 9 + 7
HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    def mass_water(n, m):
        return 100 * n * a + 100 * m * b

    def mass_sugar(k, l):
        return k * c + l * d

    def mass(n, m, k, l):
        return mass_water(n, m) + mass_sugar(k, l)

    def is_within_f(ms, mw):
        return ms + mw <= f

    def is_within_e(ms, mw):
        return ms * 100 <= mw * e

    def density(ms, mw):
        return ms / mw

    a, b, c, d, e, f = map(int, input().split())
    max_n = f // (100 * a)
    max_m = f // (100 * b)
    max_sugar = f * e / 100.0
    max_k = math.ceil(max_sugar // c)
    max_l = math.ceil(max_sugar // d)

    mass_water_set = set()
    for n in range(max_n + 1):
        for m in range(max_m + 1):
            mw = mass_water(n, m)
            if n + m > 0 and is_within_f(0, mw):
                mass_water_set.add(mw)
    mass_sugar_set = set()
    for k in range(max_k + 1):
        for l in range(max_l + 1):
            mass_sugar_set.add(mass_sugar(k, l))


    max_density = -HUGE
    max_mw = 0
    max_ms = 0
    for mw in mass_water_set:
        for ms in mass_sugar_set:
            if not (is_within_f(ms, mw) and is_within_e(ms, mw)):
                continue
            den = density(ms, mw)
            if den > max_density:
                max_density = den
                max_mw = mw
                max_ms = ms

    print(max_mw + max_ms, max_ms)

main()

Submission status: Accepted

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

for i in range(F // A+1):
    for j in range(F // B+1):
        w = A * i + B * j
        if w <= F:
            W.add(w)

for i in range(F // C+1):
    for j in range(F // D+1):
        s = C * i + D * j
        if s <= F:
            S.add(s)

max_rat = -24
for w in W:
    for s in S:
        if w + s <= F and s <= w / 100 * E and s+w!=0:
            rat = s / (s + w)
            if rat > max_rat:
                x, y, max_rat = w, s, rat

print(x + y, y)

Submission status: Accepted

Solution code:
#arc083c

a,b,c,d,e,f=map(int,raw_input().split())
x=1
y=-1
for i in xrange(0,f+1,100*a):
 for j in xrange(0,f+1-i,100*b):
  s=min(f-i-j,(i+j)*e//100)
  if i+j==0:
   continue
  for k in xrange(0,s+1,c):
   for l in xrange(0,s+1-k,d):
    if 1.0*y/x<1.0*(k+l)/(i+j):
     x=i+j
     y=k+l
print x+y,y

Submission status: Accepted

Solution code:
#arc083c

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+1-i,100*b):
  s=min(f-i-j,(i+j)*e//100)
  if i+j==0:
   continue
  for k in range(0,s+1,c):
   for l in range(0,s+1-k,d):
    if y/x<(k+l)/(i+j):
     x=i+j
     y=k+l
print(x+y,y)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

'''
戦略
すべてのパターンをfor文で回す
'''

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

V = []
max_water = 0
max_sato = 0
max_ratio = -1

maxA = F//(100*A)
maxB = F//(100*B)

waters = set()

for i in range(0, maxA+1):
    for j in range(0, maxB+1):
        water = 100*A*i + 100*B*j
        waters.add(water)

maxC = F // C
maxD = F // D
satos = set()
for k in range(0, maxC+1):
    for l in range(0, maxD+1):
        sato = C*k + D*l
        satos.add(sato)

for water in waters:
    for sato in satos:
        if water+sato > F or water+sato == 0:
            continue
        if sato > water/100 * E:
            continue
        #print(water, sato)
        ratio = sato/(water+sato)*100
        if ratio > max_ratio:
            max_water = water+sato
            max_sato = sato
            max_ratio = ratio
print(max_water, max_sato)

Submission status: Accepted

Solution code:
# coding:utf-8

input=raw_input()
list=input.split(" ")
for i in range(len(list)):
    list[i]=int(list[i])

e=list[4]
f=list[5]

# 1 2 10 20 15 200
# 17 19 22 26 55 2802

# xが取り得る値
listx=[]
a=list[0]
b=list[1]

i=0
while True:
   if i*a*100>f:
       break
   j=0
   while True:
      x=i*a*100+j*b*100
      if x>f:
          break;
      if x==0:
          j+=1
          continue;
      if x not in listx:
          listx.append(int(x))
      j+=1 
   i+=1 

# yが取り得る値
listy=[]
c=list[2]
d=list[3]

# yが水に溶け切れる最大値
f2=f*e/(100.0+e)

i=0
while True:
   if i*c>f2:
       break
   j=0
   while True:
      y=i*c+j*d
      if y>f2:
          break;
      if y not in listy:
          listy.append(int(y))
      j+=1 
   i+=1 

# 全てのxとyの組み合わせについてfを超えないか、および溶け切れるかを調べる
lengthx=len(listx)
lengthy=len(listy)

xy_max=0
y_max=0
noudo_max=0

for i in range(lengthx):
    for j in range(lengthy):
        x=listx[i]
        y=listy[j]
        if x+y>f:
            continue
        if float(y)*100/float(x)<=e:
            noudo=float(y)/(x+y)
            if noudo>=noudo_max:
                xy_max=x+y
                y_max=y
                noudo_max=noudo

message=str(xy_max)+" "+str(y_max)
print message

Submission status: Accepted

Solution code:
a,b,c,d,e,f = [int(n) for n in input().split(" ")]
dp = [-1 for n in range(f + 1)]
dp[0] = 0
for i in range(1530):
    next_dp = dp[:]
    for i,sugar in enumerate(dp):
        if sugar >= 0:
            if i + 100 * a <= f:
                next_dp[i + 100 * a] = sugar
            if i + 100 * b <= f:
                next_dp[i + 100 * b] = sugar
            if i + c <= f and ((i - sugar) * e) / 100 >= sugar + c:
                next_dp[i + c] = max(dp[i + c], sugar + c)
            if i + d <= f and ((i - sugar) * e) / 100 >= sugar + d:
                next_dp[i + d] = max(dp[i + d], sugar + d)
    dp = next_dp
answer = [0,0]
for i,d in enumerate(dp):
    if i != 0 and answer[1] <= d / i:
        answer = [i,d / i]
print(answer[0],round(answer[0] * answer[1] ))

Submission status: Accepted

Solution code:
import numpy as np

def ceil(a):
    return int(np.ceil(a))

def sol2():
    A,B,C,D,E,F = map(int, input().split(' '))
    na, nb, nc, nd = ceil(F/A/100),ceil(F/B/100),ceil(E*F/C/100),ceil(E*F/D/100) 
    sug = np.arange(0,nc).reshape(1,1,nc,1)*C+np.arange(0,nd).reshape(1,1,1,nd)*D
    wat = np.arange(0,na).reshape(na,1,1,1)*A*100+np.arange(0,nb).reshape(1,nb,1,1)*B*100
    sug2=np.unique(sug[sug<=F*F/100])
    wat2=np.unique(wat[wat<=F])
    
    if len(wat2)==1:
        print(0,0)
        return
    elif E==0:
        print(wat2[1],0)
        return
    
    tot =  wat2[1:].reshape(len(wat2[1:]),1) + sug2
    e2 = E/(100+E)
    dense = (sug2/tot)[tot<=F]
    
    maxi = np.argmax(dense[dense<=e2])
    stot = tot[tot<=F][dense<=e2]
    ssug = (sug2 + tot*0)[tot<=F][dense<=e2]
    
    if dense[maxi] ==0:
        print(wat2[1],0)
    else:
        print(int(stot[maxi]),int(ssug[maxi]))
sol2()

Submission status: Accepted

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

w = [i+j for i in range(0,f+1,100*a) for j in range(0,f+1,100*b) if i+j <= f]
s = [i+j for i in range(0,f+1,c) for j in range(0,f+1,d) if i+j <= f]

W = w[-1]
S = 0
for ww in w :
    for ss in s :
        if ww+ss > f or ww == 0:
            continue
        elif ss/(ss+ww) > S/(W+S) and e >= 100*ss/ww:
            W = ww
            S = ss

print(W+S, S)

Submission status: Accepted

Solution code:
lists = [int(i) for i in input().rstrip().split(" ")]
w_1 = 100 * lists[0]
w_2 = 100 * lists[1]
s_1 = lists[2]
s_2 = lists[3]
sol = lists[4] / (100 + lists[4])
limit = lists[5]

weight = 0
dens = 0
ans = (1,-1)
w_group = set()

for i in range(limit//w_1 + 1):
    for j in range((limit-w_1*i)//w_2 + 1):
        w_group.add(w_1*i + w_2*j)
w_group.remove(0)

s_group = set()

for w_w in w_group:
    for i in range((limit-w_w)//s_1 + 1):
         for j in range((limit-w_w-s_1*i)//s_2 + 1):
             s_group.add(s_1*i + s_2*j)
    for s_s in s_group:
        weight = w_w + s_s
        dens = s_s / weight
        if sol >= dens > ans[1]/ans[0]:
            ans = (weight, s_s)
    s_group.clear()
print("{0} {1}".format(ans[0], ans[1]))

Submission status: Accepted

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

max_density = 0
ans_water = 0
ans_sugar = 0
for na in range(F // (A * 100) + 1):
    for nb in range(F // (B * 100) + 1):
        water = (A * na + B * nb) * 100
        if water == 0 or water > F:
            break

        for nc in range(F // C + 1):
            for nd in range(F // D + 1):
                sugar = C * nc + D * nd
                if water + sugar > F:
                    break

                density = sugar / (water + sugar)
                if density > E / (100 + E):
                    break

                if density >= max_density:
                    max_density = density
                    ans_water = water
                    ans_sugar = sugar

print(ans_water + ans_sugar, ans_sugar)