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: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d,e,f = LI()
    f += 1
    a *= 100
    b *= 100
    m = [0] * f
    s = [0] * f
    m[0] = 1
    s[0] = 1
    for i in range(f-a):
        if m[i] == 1:
            m[i+a] = 1
    for i in range(f-b):
        if m[i] == 1:
            m[i+b] = 1

    for i in range(f-c):
        if s[i] == 1:
            s[i+c] = 1
    for i in range(f-d):
        if s[i] == 1:
            s[i+d] = 1

    mr = 0
    r = [0,0]
    e = e / (100+e)
    for i in range(0,f):
        if m[i] == 0:
            continue
        for j in range(1,f-i):
            if i+j >= f:
                break
            if s[j] == 0:
                continue
            k = j / (i+j)
            if k > e:
                break
            if k > mr:
                mr = k
                r = [i+j, j]

    return ' '.join(map(str,r))


print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d,e,f = LI()
    f += 1
    a *= 100
    b *= 100
    m = [0] * f
    s = [0] * f
    m[0] = 1
    s[0] = 1
    for i in range(f-a):
        if m[i] == 1:
            m[i+a] = 1
    for i in range(f-b):
        if m[i] == 1:
            m[i+b] = 1

    for i in range(f-c):
        if s[i] == 1:
            s[i+c] = 1
    for i in range(f-d):
        if s[i] == 1:
            s[i+d] = 1

    mr = 0
    r = [0,0]
    e = e / (100+e)
    for i in range(0,f):
        if m[i] == 0:
            continue
        for j in range(1,f-i):
            if i+j >= f:
                break
            if s[j] == 0:
                continue
            k = j / (i+j)
            if k > e + eps:
                break
            if k > mr:
                mr = k
                r = [i+j, j]

    return ' '.join(map(str,r))


print(main())

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)
a, b, c, d, e, f = map(int, input().split())
def dfs(g, a, b, can, base=100):
    if not g <= f:
        return
    if g in can:
        return
    can[g] = 1
    dfs(g + a, a, b, can)
    dfs(g + b, a, b, can)
can1 = {}
dfs(0, a, b, can1)
can2 = {}
dfs(0, c, d, can2, 1)

ans = (0, 0, 0)
for g in can1:
    if g == 0:
        continue
    rest = f - 100*g
    result = max([0]+[h for h in can2 if h <= min(rest, e*g)])
    ans = max(ans, (result / (100*g + result), 100*g, result))
print(ans[1]+ans[2], ans[2])

Submission status: Wrong Answer

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

A_limit = F // (100*A)

max_density = 0.0
max_suger = 0
max_total = 0

for a in range(A_limit + 1):
    B_limit = (F-100*A*a) // (100*B)
    for b in range(B_limit + 1):
        water = 100*A*a + 100*B*b
        
        suger_limit = min(water*E // 100, F - water)
        
        suger_ = 0
        for c in range(suger_limit // C + 1):
            d = (suger_limit - C*c) // D
            suger = C*c + D*d
            suger_ = max(suger, suger_)
        
        if (suger_ + water) > 0:
            if suger_ / (suger_ + water) > max_density:
                max_density = suger_ / (suger_ + water)
                max_suger = suger_
                max_total = suger_ + water

print(str(max_total)+" "+str(max_suger))

Submission status: Wrong Answer

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

w  = [False for i in range(f+1)]
s  = [False for i in range(f+1)]
w[0] = True
s[0] = True
for i in range(f+1):
    if not w[i]:
        continue
    if i+(100*a) <= f:
        w[i+(100*a)] = True
    if i+(100*b) <= f:
        w[i+(100*b)] = True
for i in range(f+1):
    if not s[i]:
        continue
    if i+c <= f//2:
        s[i+c] = True
    
    if i+d <= f//2:
        s[i+d] = True

ww = [i for i in range(1, f+1) if w[i]]
ss = [i for i in range(1, f+1) if s[i]]

max_w = 0
max_s = 0
max_r = 0
for w in ww:
    for s in ss:
        if s <= e*w/100 and s+w <= f and s/(w+s)>max_r:
            # print(w,s)
            max_r = s/(w+s)
            max_s = s
            max_w = w
print(max_w+max_s, max_s)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d,e,f = LI()
    f += 1
    a *= 100
    b *= 100
    m = [0] * f
    s = [0] * f
    m[0] = 1
    s[0] = 1
    for i in range(f-a):
        if m[i] == 1:
            m[i+a] = 1
    for i in range(f-b):
        if m[i] == 1:
            m[i+b] = 1

    for i in range(f-c):
        if s[i] == 1:
            s[i+c] = 1
    for i in range(f-d):
        if s[i] == 1:
            s[i+d] = 1

    mr = 0
    r = [0,0]
    e = e / (100+e)
    for i in range(1,f):
        if m[i] == 0:
            continue
        for j in range(1,f-i):
            if i+j >= f:
                break
            if s[j] == 0:
                continue
            k = j / (i+j)
            if k > e:
                break
            if k > mr:
                mr = k
                r = [i+j, j]

    return ' '.join(map(str,r))


print(main())

Submission status: Time Limit Exceeded

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

tmp = 0
ans_A = 0
ans_B = 0
for a in range(31):
    for b in range(31):
        x = 100 * (a * A + b * B)
        for c in range((x // 100 * E) // C + 1):
            for d in range(((x // 100 * E) - c) // D + 1):
                y = c * C + d * D
                if x + y > F or y > x * E // 100:
                    break
                if x + y != 0:
                    if y / (x + y) > tmp:
                        ans_A = x + y
                        ans_B = y
                        tmp = y / (x + y)

if ans_A == 0:
    print(100 * A, 0)
else:
    print(ans_A, ans_B)

Submission status: Time Limit Exceeded

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

tmp = 0
ans_A = 0
ans_B = 0
for a in range(31):
    for b in range(31):
        x = 100 * (a * A + b * B)
        for c in range((x // 100 * E) // C + 1):
            for d in range((x // 100 * E) // D + 1):
                y = c * C + d * D
                if x + y > F or y > x * E // 100:
                    break
                if x + y != 0:
                    if y / (x + y) > tmp:
                        ans_A = x + y
                        ans_B = y
                        tmp = y / (x + y)

if ans_A == 0:
    print(100 * A, 0)
else:
    print(ans_A, ans_B)

Submission status: Time Limit Exceeded

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

tmp = 0
ans_A = 0
ans_B = 0
for a in range(31):
    for b in range(31):
        for c in range(101):
            for d in range(101):
                x = 100 * (a * A + b * B)
                y = c * C + d * D
                if x + y <= F and y <= x * E // 100 and x + y != 0:
                    if y / (x + y) > tmp:
                        ans_A = x + y
                        ans_B = y
                        tmp = y / (x + y)

print(ans_A, ans_B)

Submission status: Time Limit Exceeded

Solution code:
a,b,c,d,e,f=map(int,input().split())
maxsugar=f*e/(100+e)
maxwater=f*100/(100+e)
#print(maxsugar,maxwater)
sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)
#print(sugar)
water=[]
for i in range(int(maxwater//100+2)//min(a,b)+5):
    for j in range(int(maxwater//100+2)//min(a,b)+5):
        y=i*a+j*b
        water.append(y)
#print(water)
water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)

Submission status: Time Limit Exceeded

Solution code:
import fractions as frac
a, b, c, d, e, f = map(int, input().split())
memo=[[(-1, -1)]*100000 for i in range(10000)]
func = lambda t: frac.Fraction(t[0], t[1] ) if t[1]>0 else -1
def dp(s, w):
    if w*e<s or w*100+s>f:
        return (-1, -1)
    m=memo[s][w]
    if m[0]>0:
        return memo[s][w]
    p0=(s,w) 
    p1=dp(s, w+a)
    p2=dp(s, w+b)
    p3=dp(s+c, w)
    p4=dp(s+d, w)
    memo[s][w]=max(p0, p1, p2, p3, p4, key = func) if w>0 else max(p1, p2, key = func)
    return memo[s][w]
    
ans=dp(0,0)
print(ans[0]+ans[1]*100, ans[0])

Submission status: Time Limit Exceeded

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(n, m, k, l):
        return 100 * n * a + 100 * m * b + k * c + l * d

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

    def is_within_f(n, m, k, l):
        return mass(n, m, k, l) <= f

    def is_within_e(n, m, k, l):
        waterp100 = n * a + m * b
        return mass_sugar(k, l) <= waterp100 * e

    def density(n, m, k, l):
        waterp100 = n * a + m * b
        return mass_sugar(k, l) / waterp100

    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)

    max_density = -0.1
    nmkl = []
    for n in range(max_n + 1):
        for m in range(max_m + 1):
            if n == m == 0:
                continue
            if not is_within_f(n, m, 0, 0):
                continue
            for k in range(max_k + 1):
                for l in range(max_l + 1):
                    if is_within_f(n, m, k, l) and is_within_e(n, m, k, l):
                        den = density(n, m, k, l)
                        if den > max_density:
                            max_density = den
                            nmkl = [n, m, k, l]

    n, m, k, l = nmkl
    print(mass(n, m, k, l), mass_sugar(k, l))

main()

Submission status: Time Limit Exceeded

Solution code:
#python3

#cups for water, spoons for sugar
cup1, cup2, spoon1, spoon2, max_density, max_volume = (int(x) for x in input().split())

possible_water_volumes = set()

for cups1_nr in range(0, 30):
    for cups2_nr in range(0, 30):
        curr_water_volume = cups1_nr * cup1 + cups2_nr * cup2
        if curr_water_volume <= max_volume and curr_water_volume != 0:
            possible_water_volumes.add(curr_water_volume)

global_optimal_sugar = 0
global_optimal_water = 0
global_dencity = 0            
for water_volume in possible_water_volumes:
    curr_optimal_sugar = water_volume * max_density
    for spoons1_nr in range(0, 1 + curr_optimal_sugar // spoon1):
        curr_sugar = spoon1 * spoons1_nr
        spoons2_nr = ((curr_optimal_sugar - curr_sugar) // spoon2)
        curr_sugar += spoon2 * spoons2_nr
        curr_density = curr_sugar / (water_volume * 100 + curr_sugar)
        if curr_sugar + water_volume * 100 > max_volume:
            continue
        elif curr_sugar > curr_optimal_sugar:
            continue
        elif curr_density >= global_dencity:
            # print(curr_sugar, water_volume)
            global_optimal_sugar = curr_sugar
            global_optimal_water = water_volume
            global_dencity = curr_density
            
sugar_water_volume = global_optimal_water * 100 + global_optimal_sugar
print(sugar_water_volume, global_optimal_sugar)

Submission status: Time Limit Exceeded

Solution code:
import collections
import numpy as np

# デバッグ用
DEBUG = False
# DEBUG = True

# 宣言
result = [0, 0] # 砂糖水の質量 砂糖の質量
max_concentration = 0
ITER_MAX = 30 
seat_list = []

# 入力部
if DEBUG:
    arg = '1 2 1 2 100 1000'

else:
    arg = input()

arg = arg.split(' ')
arg = list(map(int, arg))

A = np.arange(0, ITER_MAX + 1) * arg[0] * 100
B = np.arange(0, ITER_MAX + 1) * arg[1] * 100
C = np.arange(0, ITER_MAX * 100 + 1) * arg[2]
D = np.arange(0, ITER_MAX * 100 + 1) * arg[3]

# 処理部
for a in A:
    for b in B:
        for c in C:
            for d in D:
                # 0割りになる場合はNG
                if (a + b) == 0 :
                    continue

                concentration = 100 * (c + d) / (a + b)
                weight = (a + b) + (c + d)

                # 溶解度が条件を超えている場合はNG
                if concentration > arg[4] :
                    continue
                
                # 総量がビーカーの容量を超えている場合はNG
                if weight > arg[5] :
                    continue
                
                if (concentration > max_concentration):
                    result = [weight, c+d]
                    max_concentration = concentration

                # 溶解度がMAX値の時はループを全て抜けるようにしたい
                if concentration == arg[4]:
                    break

# 出力部
print(result[0], result[1])

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
Ans = [0,100*A,0]
def Con(water,sugar):
    return 100*(sugar)/(water+sugar)
def limit(water):
    return water*E//100
for NumA in range(1,F//(100*A)+2):
    for NumB in range(0,F//(100*B)+1):
        water = 100*(A*NumA+B*NumB)
        lim1 = limit(water)
        lim2 = F-water
        lim = min(lim1,lim2)
        for i in range(lim//D+1):
            sugar = D*i
            sugar += ((lim-sugar)//C)*C
            Con1 = Con(water,sugar)
            if Ans[0] < Con1:
                Ans = [Con1,water,sugar]
print(Ans[1]+Ans[2],Ans[2])

Submission status: Accepted

Solution code:
a,b,c,d,e,mv=map(int,input().split())
e= e/(e+100)

ans=-1
for i in range(31):
    if 100*i*a> mv: continue
    for j in range(31):
        if i+j==0:continue
        if 100*(i*a+j*b)> mv:continue
        for k in range(2801):
            if 100*(i*a+j*b)+k*c> mv:continue
            for l in range(2801):
                water=100*(a*i+b*j)
                sugar=k*c+l*d
                if water+sugar > mv:
                    break
                pp= sugar/(water+sugar)
                
                if e>= pp and ans<pp:
                    #print("water",water,"sugar",sugar,pp)
                    ans=pp
                    ans1= water+sugar
                    ans2= sugar
print(ans1,ans2)

Submission status: Accepted

Solution code:
from math import floor
A, B, C, D, E, F = map(int, input().split())
P = []
for i in range(31):
    for j in range(31):
        W=A*i+B*j
        if 100*W>F: break
        for k in range(3001):
            l = floor(min(F-100*W-C*k,W*E-C*k)/D)
            S = C*k+D*l
            if l<0 or S+W==0: continue
            P.append((100*S/(W*100+S),(W*100+S,S)))
P.sort(key=lambda x:x[0])
print(*P[-1][1])

Submission status: Accepted

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

    waters = set()
    for i in range((30 + A - 1) // A + 1):
        for j in range((30 + B - 1) // B + 1):
            a = 100 * (i * A + j * B)
            if a > F or a == 0:
                continue
            waters.add(a)

    sugars = set()
    for k in range((3000 + C - 1) // C + 1):
        for l in range((3000 + D - 1) // D + 1):
            b = k * C + l * D
            if b > F:
                continue
            sugars.add(b)

    max_density = -1
    ans = [-1, -1]
    for w in waters:
        for s in sugars:
            if w + s > F or w // 100 * E < s:
                continue
            density = 100 * s / (w + s)
            if density > max_density:
                ans = [(w + s), s]
                max_density = density
    return ans


print(*solve())

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil
a,b,c,d,e,f = ma()
la = f//(100*a)
lb = f//(100*b)
tmp = -1
ws = 0
s = 0
for ia in range(la+1):
    for ib in range(lb+1):
        water = ia*a*100 + ib*b*100
        if water>f or water==0:
            continue
        lc = (ia*a + ib*b)*e //c
        ld =(ia*a + ib*b)*e //d
        #print(water)
        #print(la,lb,lc,ld)
        for ic in range(lc+1):
            for id in range(ld+1):


                suger = ic*c + id*d
                if suger >e*(ia*a+ib*b) or suger+water>f:
                    continue
                if tmp <(suger)/(water+suger):
                    tmp = (suger)/(water+suger)
                    ws = water+suger
                    s = suger
print(ws,s)

Submission status: Accepted

Solution code:
import bisect

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

dp_w = [0] * 31
dp_w[0] = 1
for w in [a,b]:
    for i in range(w,31):
        dp_w[i] |= dp_w[i-w]

water = []
for i in range(1,31):
    if(dp_w[i]==1):
        water.append(i*100)

dp_s = [0] * 1600
dp_s[0] = 1
for w in [c,d]:
    for i in range(w,1600):
        dp_s[i] |= dp_s[i-w]

sugar = []
for i in range(1600):
    if(dp_s[i]==1):
        sugar.append(i)

ans_w =water[0]
ans_s = 0

for wi in water:
    if(f < wi):
        continue
    max_s = min(wi//100 * e, f-wi)
    ind = bisect.bisect_right(sugar,max_s)
    if(ind==0):
        continue
    si = sugar[ind-1]

    if( (ans_w + ans_s) * si > (wi+si) * ans_s):
        ans_w = wi
        ans_s = si

print('{} {}'.format(ans_w+ans_s,ans_s))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

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


ok = [0]*3001
for i in range(0,3001,c):
    ok[i] = 1

for i in range(3001):
    if ok[i] and i+d <= 3000:
        ok[i+d] = 1

#print(ok[:30])

ans = (0.0,100*a,0)

for x in range(31):
    for y in range(31):
        p = x*100*a + y*100*b
        if p==0: continue
        if p > f: break
        for q in range(min(f-p,e*p//100),-1,-1):
            if ok[q]:
                v = q/(p+q)
                if v > ans[0]:
                    ans = (v,p+q,q)
                break
        
print(*ans[1:])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
dp=[0]*(f+1)
w=[]
s=[]
for i in range(f+1):
  if i%(a*100)==0:dp[i]=i
  if i%(b*100)==0:dp[i]=i
  if i>a*100 and dp[i-a*100]:dp[i]=i
  if i>a*100 and dp[i-b*100]:dp[i]=i
for i in dp:
  if i:w.append(i)
m=w[-1]*e//100+1
dp=[0]*(m)
for i in range(m):
  if i%c==0:dp[i]=i
  if i%d==0:dp[i]=i
  if i>c and dp[i-c]:dp[i]=i
  if i>d and dp[i-d]:dp[i]=i
for i in dp:
  if i: s.append(i)
g=0
ans=(w[0],0)
for i in w:
  for j in s:
    if i+j<=f and g<j/(i+j)<=e/(100+e):
      g=j/(i+j)
      ans=(i+j,j)
print(*ans)

Submission status: Accepted

Solution code:
from itertools import product
def main():
    a, b, c, d, e, f = list(map(int, input().split()))
    max_con = -1
    ans_w, ans_s = 0, 0
    W, S = [], []
    a *= 100
    b *= 100
    for i, j in product(range(f // a + 1), range(f // b + 1)):
        if (w := a * i + b * j) <= f:
            W.append(w)
    for i, j in product(range(f // c + 1), range(f // d + 1)):
        if (s := c * i + d * j) <= f:
            S.append(s)
    for w, s in product(W, S):
        if w == s == 0:
            continue
        if w * e >= 100 * s and (con := 100 * s / (w + s)) > max_con and w + s <= f:
            max_con = con
            ans_w, ans_s = w, s

    print(' '.join([str(ans_w + ans_s), str(ans_s)]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import bisect
    a, b, c, d, e, f = map(int, input().split())
    a = a * 100
    b = b * 100
    g = f * e // 100
    wtr = [0] * f
    sgr = [0] * g
    wtr[0] = 1
    sgr[0] = 1
    wtr_l = []
    sgr_l = []


    def comb(lmt, tgt, lis):
        for i in range(lmt - tgt):
            if lis[i] != 0:
                lis[i + tgt] = 1


    comb(f, a, wtr)
    comb(f, b, wtr)
    comb(g, c, sgr)
    comb(g, d, sgr)

    for i, w in enumerate(wtr):
        if i == 0:
            continue
        elif w == 1:
            wtr_l.append(i)

    for j, s in enumerate(sgr):
        if s == 1:
            sgr_l.append(j)

    res = -1
    ans = []
    for wt in wtr_l:
        pct = min(f - wt, wt * e // 100)
        sid = bisect.bisect_left(sgr_l, pct)
        if pct in sgr_l:
            sgr_max = sgr_l[sid]
        else:
            sgr_max = sgr_l[sid - 1]
        pct_max = 100 * sgr_max / (wt + sgr_max)
        if pct_max > res:
            res = pct_max
            ans.append((wt + sgr_max, sgr_max))
    print(*ans[-1])
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
a, b, c, d, e, f = map(int, input().split())
a = a * 100
b = b * 100
g = f * e // 100
wtr = [0] * f
sgr = [0] * g
wtr[0] = 1
sgr[0] = 1
wtr_l = []
sgr_l = []


def comb(lmt, tgt, lis):
    for i in range(lmt - tgt):
        if lis[i] != 0:
            lis[i + tgt] = 1


comb(f, a, wtr)
comb(f, b, wtr)
comb(g, c, sgr)
comb(g, d, sgr)

for i, w in enumerate(wtr):
    if i == 0:
        continue
    elif w == 1:
        wtr_l.append(i)

for j, s in enumerate(sgr):
    if s == 1:
        sgr_l.append(j)

res = -1
ans = []
for wt in wtr_l:
    pct = min(f - wt, wt * e // 100)
    sid = bisect.bisect_left(sgr_l, pct)
    if pct in sgr_l:
        sgr_max = sgr_l[sid]
    else:
        sgr_max = sgr_l[sid - 1]
    pct_max = 100 * sgr_max / (wt + sgr_max)
    if pct_max > res:
        res = pct_max
        ans.append((wt + sgr_max, sgr_max))
print(*ans[-1])

Submission status: Accepted

Solution code:
from itertools import product

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

lima = [100 * a * i for i in range(f // (100 * a) + 1)]
limb = [100 * b * i for i in range(f // (100 * b) + 1)]
setw = set([i + j for i, j in product(lima, limb) if 0 < i + j <= f])
limc = [c * i for i in range(f // c + 1)]
limd = [d * i for i in range(f // d + 1)]
sets = set([i + j for i, j in product(limc, limd) if 0 < i + j <= f])

cnt, ans = 0, (max(setw), 0)
for w in setw:
    for s in sets:
        if (cnt <= 100 * s / w <= e) and (s + w <= f):
            cnt = 100 * s / w
            ans = s + w, s
else:
    print(*ans)

Submission status: Accepted

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

water = []
sugar = []
for i in range(0,1000):
    for j in range(0,1000):
        if (100*i*a + 100*j*b ) <= f:
            water.append(100*i*a + 100*j*b)
        if c*i + d*j <= f:
            sugar.append(c*i+d*j)
        

water = list(set(water))
water.sort()
water.remove(0)
sugar = list(set(sugar))
sugar.sort()

concentration = 0
sgw = 0
sg = 0

x = e/100

for i in water:
    for j in sugar:
        temp = (100 * j) / (i + j)
        if concentration <= temp and i + j <= f and (i /100)*e  >= j:
            #print(i,j,concentration,temp,i*x)
            sgw = i + j
            sg = j
            concentration = temp
if sgw == 0:
    sgw = water[-1]
print(sgw,sg)

Submission status: Accepted

Solution code:
#!python3

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


def main():
    ans = (0, 0, 0)
    for a in range(0, F + 1, 100 * A):
        for b in range(0, F + 1, 100 * B):
            if a == 0 and b == 0:
                continue
            water = a + b
            if water > F:
                break
            s = min(F - water, water // 100 * E)
            sugar = 0
            for c in range(0, s + 1, C):
                t = s - c
                sugar = max(sugar, c + (t // D) * D)
            ans = max(ans, (sugar / water, water + sugar, sugar))
    
    print(ans[1], ans[2])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
# 100(Ax + By) + Cz + Dw <= F
# 100(Cz + Dw) / (100(Ax + By) + Cz + Dw) <= E
SD = {}
WD = {}
MS = (E * F) // (100 + E)
for i in range(MS // C + 1):
  for j in range((MS - i * C) // D + 1):
    SD[i*C+j*D] = 1
Sup = F // (100 * A)
wans, sans = 0, 0
for i in range(Sup+1):
  SUp = (F - 100 * A * i) // (100 * B)
  for j in range(SUp+1):
    W = 100 * (A * i + B * j)
    if i != 0 or j != 0:
      for S in SD:
        if W + S <= F and 100 * S <= W * E:
          if wans == 0 and sans == 0:
            wans, sans = W + S, S
          else:
            if sans * (S + W) < S * wans:
              wans, sans = W + S, S
print(wans, sans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
L = []
for p in range(f//a+1):
    for q in range((f-a*p)//b+1):
        h = 100*(a*p+b*q)
        for r in range((f-h)//c+1):
            for s in range((f-h-c*r)//d+1):
                g = c*r+d*s
                if g+h !=0:
                    bool1 = (g/(g+h) <= e/(100+e))
                    if bool1 and g+h <= f:
                        if h !=0:
                            L.append((100*g/(g+h),g+h,g))
L.sort(reverse = True)  
#print(L)
print(L[0][1],L[0][2])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
ms = 0
mt = 100
for i in range(f//(100*a) + 1):
    for j in range((f-100*i*a)//(100*b) + 1):
        for k in range((f-i*a*100 - j*b*100)//(c)+1):
            for l in range((f-i*a*100 - j*b*100-k*c)//(d)+1):
#                print(i, j, k, i*a*100 + j*b*100+c*k+d*l)
                ss, tt = c*k+d*l, i*a*100 + j*b*100+c*k+d*l
                if ss*100 > e*(tt-ss):
                    continue
                if ss*mt >= tt*ms:
                    ms, mt = ss, tt
print(mt, ms)
#        if i*a*100 + j*b*100 > f:
#            break

Submission status: Accepted

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

conc = 0
total = 0

ans = [100 * A,0]

for a in range(0,31):
  for b in range(0,31):
    water = (A * a + B * b) * 100
    if water > F:
      break
    else:
      for c in range(3001):
        water = (A * a + B * b) * 100
        if water == 0:
          break
        #探索中の水量に解かせる砂糖の量
        sugar_limit = int(water * E / 100)
        #操作Cで投入された砂糖の量
        sugarC = c * C
        
        if sugarC > sugar_limit:
          break
        #ビーカーに溶かせる容量
        else:
          rest = F - water - sugarC
          #水に溶かせられる砂糖量
          sugar_rest = sugar_limit - sugarC
          
          if rest < 0:
            break
          
          else:
            #操作Dで溶かせられる砂糖領
            sugarD = (min(rest,sugar_rest) // D) * D
            sugar = sugarC + sugarD
            temp = (sugar) / (water + sugar)
            if conc < temp and temp < E:
              conc = temp
              total = water + sugar
              ans = [total,sugar]
        
print(ans[0],ans[1])

Submission status: Accepted

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

noudo = 0
ans = (100*A, 0)
for a in range(31):
    for b in range(31):
        water = A * a + B * b
        if water*100 > F:
            break
        for c in range(3001):
            water = A * a + B * b
            if water == 0:
                break
            can_sugar = water * E
            if C * c > can_sugar:
                break
            rest = F - water * 100 - C*c
            if rest < 0:
                break
            rest_sugar = can_sugar - C * c
            sugar = (min(rest_sugar, rest) // D) * D
            tmp = (sugar + C*c) / (water + sugar + C*c)
            if noudo < tmp:
                noudo = tmp
                ans = (water*100 + C*c + sugar, c*C + sugar)

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