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())
kouho = 0
jisho = {}
max_a = 30 // a
max_b = 30 // b
for i in range(max_a + 1):
    for j in range(max_b + 1):
        water = (a * i + b * j) * 100
        if water == 0:
            continue
        lim1 = e * (a * i + b * j)
        lim2 = f - water
        lim = min(lim1, lim2)
        max_c = lim // c
        max_d = lim // d
        for k in range(max_c + 1):
            for m in range(max_d + 1):
                sugar = k * c + m * d
                if sugar > lim:
                    continue
                satoumizu = water + sugar
                if satoumizu > f:
                    continue
                if sugar == 0:
                    continue

                noudo = 100 * sugar / satoumizu
                if noudo > kouho:
                    kouho = noudo
                    jisho[noudo] = (sugar, satoumizu)
if kouho == 0:
    print(100 * a, 0)
    exit()
ans2, ans1 = jisho[kouho]
print(ans1, ans2)

Submission status: Accepted

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

dp=[[False]*(f+2) for i in range(f+2)]
# dp[i][j]: iは入れた砂糖の重さ、jは水、値は濃度

dp[0][0]=True

for j in range(f+1):
    i=0
    if dp[i][j] and j<=f:
        if 0<i+j+100*a<=f:
            dp[i][j+100*a]=True
        if 0<i+j+100*b<=f:
            dp[i][j+100*b]=True

for i in range(f+1):
    for j in range(1,f+1):
        if dp[i][j] and i+j<=f:
            if 0<i+c+j<=f:
                dp[i+c][j]=True
            if 0<i+d+j<=f:
                dp[i+d][j]=True

tmpi=0
tmpj=min(a*100,b*100)
for i in range(f+1):
    for j in range(1,f+1):
        if dp[i][j] and i*100<=e*j and 0<j+i<=f and tmpi*j<i*tmpj:
            tmpi=i
            tmpj=j
        if i*100==e*j:
            break

print(tmpi+tmpj, tmpi)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
a,b,e = 100*a,100*b,e/(100+e)
best = [max(0,(f//a)*a,(f//b)*b),0,0] #[sugarwater,sugar,concentration]

for n in range(f//a+1):
    na = n*a
    for m in range((f-na)//b+1):
        if n==m==0:
            continue
        mb = m*b
        for k in range((f-na-mb)//c+1):
            kc = k*c
            for l in range((f-na-mb-kc)//d+1):
                ld = l*d
                sugar = (kc+ld)
                sugarwater = (na+mb+kc+ld)
                if best[2] < sugar/sugarwater <= e:
                    best = [sugarwater,sugar,sugar/sugarwater]
                
best.pop()
print(*best)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    water = set()
    for a in range(F // (A * 100) + 1):
        for b in range(F // (B * 100) + 1):
            if 0 < a * 100 * A + b * 100 * B <= F:
                water.add(a * 100 * A + b * 100 * B)

    kouho = []
    for w in water:
        ma = (E * w) // 100
        for c in range(ma // C + 1):
            for d in range(ma // D + 1):
                sugar = c * C + d * D
                if 0 < sugar <= ma and w + sugar <= F:
                    kouho.append([w, sugar])

    if len(kouho) == 0:
        print(list(water)[0], 0)
        exit()

    max_noudo = 0
    res = []
    for w, sugar in kouho:
        noudo = sugar / (w + sugar)
        if max_noudo < noudo:
            max_noudo = noudo
            res = [w + sugar, sugar]
    print(*res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

dp = [[-1]*3 for _ in range(f + 1)]
dp[0] = [0, 0, 0]
for i in range(1, f+1):
    lst = []
    if i >= 100*a and dp[i-100*a][1] != -1:
        h = dp[i-100*a][2] / i
        lst.append([h, dp[i-100*a][1] + 100*a, dp[i-100*a][2]])
    if i >= 100*b and dp[i-100*b][1] != -1:
        h = dp[i-100*b][2] / i
        lst.append([h, dp[i-100*b][1] + 100*b, dp[i-100*b][2]])
    if i >= c and dp[i-c][1] > 0:
        h = (dp[i-c][2] + c) / i
        if h <= e/(100 + e):
            lst.append([h, dp[i-c][1], dp[i-c][2] + c])
    if i >= d and dp[i-d][1] > 0:
        h = (dp[i-d][2] + d) / i
        if h <= e/(100 + e):
            lst.append([h, dp[i-d][1], dp[i-d][2] + d])
    if lst:
        dp[i] = max(lst)
ans = max(dp)
print(ans[1] + ans[2], ans[2])

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
"""
100a 水 <= 30
100b 水 <= 30
c 砂糖 <= 30
d 砂糖 <= 30
e 100gにとける砂糖の量
f 最大質量

全探索の時間ですか！？ 高々 30*30*1000*1000 工夫っすれば  oK.
"""
ans = 0
ansl = [a*100, 0]
for a_times in range(f//(a*100) + 1):
	a_g = a_times * a * 100
	for b_times in range(f//(b*100) + 1):
		b_g = b_times * b * 100
		for c_times in range(f//c + 1):
			c_g = c_times * c
			for d_times in range(f//d + 1):
				d_g = d_times * d
				targ = a_g+b_g+c_g+d_g
				if targ > f:
					break
				elif targ != 0:
					if (a_g+b_g)//100*e >= c_g+d_g:
						if (c_g+d_g)/targ > ans:
							ans = (c_g+d_g)/targ
							ansl = [targ, c_g+d_g]
print(*ansl)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
ws = []
for i in range(f//100//a+1):
    for j in range(f//100//b+1):
        w = 100*(a*i+b*j)
        if 0 < w <= f:
            ws.append(w)
        if w >= f:
            break
ss = []
for i in range(f*e//(100+e)//c+1):
    for j in range(f*e//(100+e)//d+1):
        s = c*i+d*j
        if 0 <= s <= f*e//(100+e):
            ss.append(s)
n = []
for w in ws:
    for s in ss:
        if w+s > f:
            continue
        if s > e*w//100:
            continue
        n.append((s/(w+s), w+s, s))

nmax = max(n, key=lambda x:x[0])
print(nmax[1], nmax[2])

Submission status: Accepted

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

import numpy
from queue import deque

def main():
  l = list(map(int, input().split()))
  w1, w2, s1, s2, spwr, mm = l
  w1, w2 = 100*w1, 100*w2
  flags = numpy.zeros((mm+1, mm+1))
  dq = deque([(w1, 0)])
  max_conc = -1.0
  ans = (0, 0)
  while dq:
    w, s = dq.pop()
    flags[w, s] = 1
    if w != 0 and s <= spwr * w // 100:
      conc = s / (w + s)
      if max_conc < conc:
        max_conc = conc
        ans = (w+s, s)
    for sx in [s1, s2]:
      if w + s+sx <= mm and flags[w, s+sx] == 0:
        flags[w, s+sx] = 1
        dq.append((w, s+sx))
    for wx in [w1, w2]:
      if w+wx + s <= mm and flags[w+wx, s] == 0:
        flags[w+wx, s] = 1
        dq.append((w+wx, s))
  print(*ans)
  
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
sugar = []
for i in range(1501):
    if (i%c==0):
        sugar.append(i)
    else:
        for j in range(i//c+1):
            if (i-j*c)%d==0:
                sugar.append(i)
#print(sugar)
ans = 0
ax = 100*a
ay = 0
for i in range(30):
    for j in range(30):
        if (i==0 and j==0):
            continue
        if (a*i+b*j <= f//100):
            w = (a*i+b*j)*100
            for k in sugar:
                if ((100*k)/(w+k)<=(100*e)/(100+e) and (w+k)<=f):
                    if ((100*k)/(w+k) > ans):
                        
                        ans = 100*k/(w+k)
                        #print(w,k,ans)
                        ax = w
                        ay = k
print(ax+ay,ay)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
dp = [[False] * 3001 for _ in range(3001)]
dp[0][0] = True
satomizumax = 0
satomax = 0
for sm in range(f + 1):
    for sg in range(f + 1):
        # // 4toori
        # sg/sm <= e/(100+e)
        if sg * (100 + e) > e * sm:
            break

        if dp[sm][sg]:
            if satomax * sm <= sg * satomizumax:
                satomizumax = sm
                satomax = sg
            if sm + 100 * a <= f + 1:
                dp[sm + 100 * a][sg] = True
            if sm + 100 * b <= f + 1:
                dp[sm + 100 * b][sg] = True
            if sm + c <= f + 1 and sg + c <= f + 1:
                dp[sm + c][sg + c] = True
            if sm + d <= f + 1 and sg + d <= f + 1:
                dp[sm + d][sg + d] = True
print(satomizumax, satomax)

Submission status: Accepted

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

# 作れる水の量を全探索（せいぜい30種類）
# 各水の量に対して、溶かせる砂糖の最大値は決まる（DPする）
# 最大値とすることができる砂糖に最も近づいたら割合を求め、答えの最大値を更新する

A,B,C,D,E,F = map(int,readline().split())
max_rate = -1
ans_water = 0
ans_sugar = 0
for a in range(30):
  for b in range(30):
    if a * A * 100 + b * B * 100 >= F:
      continue
    water = a * A * 100 + b * B * 100
    if water == 0:
      continue
    max_sugar = water * E // 100 # 溶ける砂糖の最大値
    if max_sugar + water > F:
      max_sugar = F - water
      
    dp = [False] * (max_sugar + 1)
    dp[0] = True
    for i in range(len(dp)):
      if dp[i]:
        if i + C >= len(dp):
          break
        dp[i + C] = True
    
    for i in range(len(dp)):
      if dp[i]:
        if i + D >= len(dp):
          break
        dp[i + D] = True
        
    for i in range(len(dp) - 1, -1, -1):
      if dp[i]:
        rate = (i * 100) / (water + i)
        break
    if rate >= max_rate:
      max_rate = rate
      ans_water = water
      ans_sugar = i
    
print(ans_water + ans_sugar,ans_sugar)

Submission status: Accepted

Solution code:
a , b , c , d , e , f = map(int,input().split())
midp = [-1 for i in range(f+1)]
mizu = []
midp[0] = 0
for i in range(f+1):
    if midp[i] != -1:
        if i + a*100 <= f and midp[i+a*100] != 0:
            midp[i+a*100] = 0
            mizu.append(i+a*100)
        if i + b*100 <= f and midp[i+b*100] != 0:
            midp[i+b*100] = 0
            mizu.append(i+b*100)
ans = 0
cou = [a*100,0]
for i in mizu:
    sai = i*e//100
    sadp = [-1 for f in range(sai+1)]
    sadp[0] = 0
    maxsa = 0
    for j in range(sai+1):
        if sadp[j] != -1:
            if j + c <= sai and i + j + c <= f and sadp[j+c] != 0:
                sadp[j+c] = 0
                maxsa = max(maxsa,j+c)
            if j + d <= sai and i + j + d <= f and sadp[j+d] != 0:
                sadp[j+d] = 0
                maxsa = max(maxsa,j+d)
    if ans < maxsa/(i+maxsa):
        ans = maxsa/(i+maxsa)
        cou = [i+maxsa,maxsa]

print(*cou)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

LI = lambda: list(map(int, input().split()))

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


def main():
    ans = (0, 0, 0)
    for b in range(F // 100 // B + 1):
        water = 100 * B * b
        for a in range((F - water) // 100 // A + 1):
            water += 100 * A * a
            if water == 0:
                continue
            # 砂糖の許容量
            s = min(F - water, water // 100 * E)
            for d in range(s // D + 1):
                sugar = d * D
                sugar += (s - sugar) // C * C
                t = (sugar / (water + sugar), water + sugar, sugar)
                if ans < t:
                    ans = t
    print(*ans[1:])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	A, B, C, D, E, F = NMI()
	W = []
	for i in range(31):
		for j in range(16):
			if 0 < (A*i + B*j) * 100 <= F:
				W.append(A*i + B*j)
	W = set(W)
	S = set()
	for i in range(3001):
		if C*i > 30 * E:
			break
		for j in range(1501):
			if 0 < C*i + D*j <= 30 * E:
				S.add(C*i + D*j)
	con = 0
	ans = [100*A, 0]
	for w in W:
		for s in S:
			if s <= F - 100 * w and s <= w * E and 100 * s / w >= con:
				con = 100 * s / w
				ans = [100*w + s, s]
	print(ans[0], ans[1])



if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

# ここから書き始める
a, b, c, d, e, f = map(int, input().split())
density = 0
ans = [100 * a, 0]
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                s = c * k + d * l
                total = s + 100 * a * i + 100 * b * j
                if total > f or total == 0 or s / total > e / (100 + e):
                    continue
                if s / total > density:
                    density = s / total
                    ans = [total, s]
print(*ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
a=100*a
b=100*b
dp1=[0]*(f+1)
dp2=[0]*(f+1)
for i in range(f+1):
    if i%a==0:
        if i+a<=f:
            dp1[i+a]=1
for i in range(f+1):
    if i==0 or dp1[i]==1:
        if i+b<=f:
            dp1[i+b]=1
for i in range(f+1):
    if i%c==0:
        if i+c<=f:
            dp2[i+c]=1
for i in range(f+1):
    if i==0 or dp2[i]==1:
        if i+d<=f:
            dp2[i+d]=1

ans=[-1,-1,-1]
for i in range(f+1):
    if dp1[i]==1:
        x=min(f-i,(i//100)*e)
        k=-1
        for j in range(x,-1,-1):
            if dp2[j]==1 or j==0:
                k=j
                if ans[0]<100*k/(i+k):
                    ans=[100*k/(i+k),i+k,k]
                break
print(str(ans[1])+" "+str(ans[2]))

Submission status: Accepted

Solution code:
from bisect import bisect_right
a, b, c, d, e, f = map(int, input().split())
waters = set(i*a+j*b if (i*a+j*b)*100<=f else 0 for i in range(31) for j in range(31))
sugers = list(set(i*c+j*d if i*c+j*d<=f else 0 for i in range(1501) for j in range(1501)))
sugers.sort()
ans_water = 0
ans_suger = 0
ans_conc = -1
for water in waters:
    if water==0:
        continue
    tmp = bisect_right(sugers, e*water)-1
    while tmp>=0:
        suger = sugers[tmp]
        if water*100+suger<=f:
            break
        tmp -= 1
    if ans_conc < suger/(water*100+suger):
        ans_conc = suger/(water*100+suger)
        ans_suger = suger
        ans_water = water*100
print(ans_water+ans_suger, ans_suger)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans = 0
answ = A*100
anss = 0
for a in range(30//A+1):
    for b in range((30-a*A)//B+1):
        # print(a, b)
        w = (a*A + b*B) * 100
        if w > F:
            break
        elif w == 0:
            continue
        # print(a, b)
        sc = (w / 100) * E
        # print(E, sc)
        for c in range(int(sc//C)+1):
            for d in range(int((sc-c*C)//D)+1):
                s = c*C + d*D
                if s > sc or w + s > F:
                    break
                tmp = s / (w + s)
                # print(a, b, s, sc, tmp)
                if ans < tmp:
                    ans = tmp
                    answ = w
                    anss = s
print(answ+anss, anss)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    A, B, C, D, E, F = map(int, input().split())
    W = set()
    for a in range(F // (100 * A) + 1):
        for b in range(F // (100 * B) + 1):
            if 0 < 100 * A * a + 100 * B * b <= F:
                W.add(100 * A * a + 100 * B * b)
    W = sorted(list(W))
    kouho = []
    for w in W:
        max_S = (w // 100) * E
        tmp = 0
        for c in range(0, max_S + 1, C):
            for d in range(0, max_S + 1 - c, D):
                s = c + d
                if s + w <= F:
                    tmp = max(tmp, s)
        kouho.append([w + tmp, tmp])

    ma = 0
    res = [W[0], 0]
    for total, sugar in kouho:
        noudo = (sugar * 100) / total
        if ma < noudo:
            ma = noudo
            res = [total, sugar]

    print(*res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
able_water=[]
for na in range(1+f//(a*100)):
  for nb in range(1+(f-na*a*100)//(b*100)):
    water=na*a*100+nb*b*100
    if water and water<=f:
      able_water.append(water)
able_water.sort()
import bisect
from fractions import Fraction
ans=[0,0,0]
max_s=(f*e+100-1)//100
for nd in range(1+max_s//d):
  for nc in range(1+(max_s-nd*d)//c):
    sugger=nc*c+nd*d
    min_water=(sugger*100+e-1)//e
    if min_water+sugger>f:continue
    idx=bisect.bisect_left(able_water,min_water)
    if idx <len(able_water) and able_water[idx]+sugger<=f:
      if ans[0]<=Fraction(sugger,(able_water[idx]+sugger)):
        ans=[Fraction(sugger,(able_water[idx]+sugger)),able_water[idx]+sugger,sugger]
print(ans[1],ans[2])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
able_water=[]
for na in range(1+f//(a*100)):
  for nb in range(1+(f-na*a*100)//(b*100)):
    water=na*a*100+nb*b*100
    if water and water<=f:
      able_water.append(water)
able_water.sort()
import bisect
ans=[0,0,0]
max_s=(f*e+100-1)//100
for nd in range(1+max_s//d):
  for nc in range(1+(max_s-nd*d)//c):
    sugger=nc*c+nd*d
    min_water=(sugger*100+e-1)//e
    if min_water+sugger>f:continue
    idx=bisect.bisect_left(able_water,min_water)
    if idx <len(able_water) and able_water[idx]+sugger<=f:
      if ans[0]<=(100*sugger/(able_water[idx]+sugger)):
        ans=[100*sugger/(able_water[idx]+sugger),able_water[idx]+sugger,sugger]
print(ans[1],ans[2])

Submission status: Accepted

Solution code:
def main():
    a, b, c, d, e, f = map(int, input().split())
    x, y = set(), set()
    for i in range(f // (100 * a) + 1):
        for j in range((f - 100 * a * i) // (100 * b) + 1):
            x.add(100 * a * i + 100 * b * j)
    for i in range(f // c + 1):
        for j in range((f - c * i) // d + 1):
            y.add(c * i + d * j)
    m = (-1, -1, -1)
    for xi in x:
        for yi in y:
            if xi == 0:
                continue
            if xi + yi > f:
                continue
            if 100 * yi > xi * e:
                continue
            s = yi / (xi + yi)
            if s > m[0]:
                m = (s, xi + yi, yi)
    print(m[1], m[2])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100
    m = (-1, 0, 0)
    for i in range(f // a + 1):
        for j in range((f - (a * i)) // b + 1):
            ma = a * i + b * j
            if ma == 0:
                continue
            for k in range((f - ma) // c + 1):
                if 100 * c * k > ma * e:
                    break
                for l in range((f - (ma + c * k)) // d + 1):
                    mb = c * k + d * l
                    if 100 * mb > ma * e:
                        break
                    dab = mb / (ma + mb)
                    if dab > m[0]:
                        m = (dab, ma + mb, mb)
    print(m[1], m[2])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = (0, 100*a)
def dfs(c_s,c_w, idx):
    global ans
    if idx == 4:
        if c_w + c_s > f:
            return
        if e*(c_w // 100) < c_s:
            return
        if c_w+c_s == 0:
            return
        if c_s / (c_w+c_s) > ans[0] / (ans[0]+ans[1]):
            ans = (c_s, c_w)
    else:
        t = [a, b, c, d][idx]
        for i in range(((f-(c_s+c_w)) // t)+1):
            if idx <= 1:
                dfs(c_s, c_w + 100 * t * i, idx + 1)
            else:
                dfs(c_s + t*i, c_w, idx + 1)
dfs(0, 0, 0)
print(*[ans[0]+ans[1], ans[0]])

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,b,c,d,e,f=MI()
wasser=[]
g=f//100
for i in range(int(f/a)+1):
    for j in range(int(f/a)+1):
        if a*i+b*j<=f//100:
            wasser.append(100*(a*i+b*j))
water=list(set(wasser))
water.sort()
#print(water)
sugar=[]
for x in water:
    sugar.append((min(f-x,e*x//100)))
#print(sugar)
sugmx=[]
for s in sugar:
    mx=0
    for i in range(s//c+1):
        for j in range(s//c+1):
            if mx<=c*i+d*j<=s:
                mx=c*i+d*j
    sugmx.append(mx)
#print(sugmx)
mix=-inf
for i in range(1,len(water)):
    u=sugmx[i]/water[i]
    #print(u)
    if u>=mix:
        mix=u
        ans1=sugmx[i]
        ans2=water[i]
print(ans2+ans1,ans1)

Submission status: Accepted

Solution code:
# coding: utf-8
# hello worldと表示する
import sys
import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

a,b,c,d,e,f=MI()
wasser=[]
g=f//100
for i in range(int(f/a)+1):
    for j in range(int(f/a)+1):
        if a*i+b*j<=f//100:
            wasser.append(100*(a*i+b*j))
water=list(set(wasser))
water.sort()
#print(water)
sugar=[]
for x in water:
    sugar.append((min(f-x,e*x//100)))
#print(sugar)
sugmx=[]
for s in sugar:
    mx=0
    for i in range(s//c+1):
        for j in range(s//c+1):
            if mx<=c*i+d*j<=s:
                mx=c*i+d*j
    sugmx.append(mx)
#print(sugmx)
mix=-inf
for i in range(1,len(water)):
    u=sugmx[i]/water[i]
    #print(u)
    if u>=mix:
        mix=u
        ans1=sugmx[i]
        ans2=water[i]
print(ans2+ans1,ans1)

Submission status: Accepted

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

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 w+s > f:
                    break
                else:
                    if w/100 * e >= s:
                        density = 100*s/(w+s)
                        tmp[w, s] = density

mxv = max(tmp, key=tmp.get)
print(mxv[0]+mxv[1], mxv[1])