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:
def solve():


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

    #memo
    list = {}

    #操作1-4
    ope1 = 100 * A
    ope2 = 100 * B
    ope3 = C
    ope4 = D


    for i in range(31):
        for j in range(31):
            for k in range(101):
                for l in range(101):
                    w_sum = i * ope1 + j * ope2
                    s_sum = k * ope3 + l * ope4
                    if w_sum == 0:
                        break
                    if w_sum+s_sum > F:
                        break
                    else:
                        if w_sum/100 * E >= s_sum:
                            p_tmp = (s_sum / (w_sum + s_sum)) * 100
                            list[i, j, k, l] = p_tmp

    max_v = max(list.values())

    for k, v in list.items():
        if v == max_v:
            print(ope1*k[0] + ope2*k[1] + ope3*k[2] + ope4*k[3], ope3*k[2] + ope4*k[3])
            break

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                elif targ==0:
                    break
                elif s>e*w/100:
                    break
                elif  mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=a*100
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,1000):
            for l in range(0,1000):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                targ=w+s
                if targ>f:
                    break
                if targ==0:
                    break
                if  s<=e*w/100  and mx<s/(w+s):
                    mx=s/targ
                    swmx=targ
                    smx=s
print(swmx,smx)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
mx=0
swmx=100*a
smx=0
 
for i in range(0,31):
    for j in range(0,31):
        for k in range(0,51):
            for l in range(0,51):
                w=0
                s=0
                w+=100*a*i+100*b*j
                s+=c*k+d*l
                if w+s<=f and s<=e*w/100 and w!=0 and mx<100*s/(w+s):
                    mx=100*s/(w+s)
                    swmx=w+s
                    smx=s
print(swmx,smx)

Submission status: Accepted

Solution code:
def main():
    water_a, water_b, sugar_c, sugar_d, max_sugar, max_mass = map(int, input().split())
    op_a = 30 // water_a
    op_b = 30 // water_b
    op_c = 3000 // sugar_c
    max_concentration = [water_a * 100, 0]
    for times_a in range(op_a + 1):
        for times_b in range(op_b + 1):
            for times_c in range(op_c + 1):
                now_water = water_a * times_a + water_b * times_b
                now_sugar_lim = now_water * max_sugar
                now_water *= 100
                now_sugar = sugar_c * times_c
                now_mass = now_water + now_sugar
                if max_mass < now_mass or now_water == 0 or now_sugar_lim < now_sugar:
                    break
                add = (min(max_mass - now_mass, now_sugar_lim - now_sugar) // sugar_d) * sugar_d
                now_mass += add
                now_sugar += add
                if now_mass * max_concentration[1] < sum(max_concentration) * now_sugar and now_sugar <= now_sugar_lim:
                    max_concentration = [now_water, now_sugar]
    print(sum(max_concentration), max_concentration[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

mx_rate = 0
ans_water = 0
ans_sugar = 0
for i in range(31):
    for j in range(31):
        total = (i * A + j * B) * 100
        if total > F:
            continue
        sugar_limit = min(F - total, (total // 100) * E)
        if sugar_limit > 0:
            for k in range(sugar_limit // C + 1):
                sugar_total = k * C
                if sugar_total < sugar_limit:
                    sugar_total += ((sugar_limit - sugar_total) // D) * D
                rate = 100 * sugar_total / (sugar_total + total)
                if rate >= mx_rate:
                    mx_rate = rate
                    ans_water = total + sugar_total
                    ans_sugar = sugar_total
print(ans_water, ans_sugar)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

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

    for p in range(F // (100 * A) + 1):
        for q in range(0, (F - 100 * A * p) // (100 * B) + 1):
            upper = (A * p + B * q) * E
            water = (A * p + B * q) * 100
            if water == 0: continue
            for r in range(0, upper // C + 1):
                if water + C * r > F: continue
                s = (upper - C * r) // D
                while s >= 0 and water + C * r + D * s > F: s -= 1
                if s < 0: continue
                if sugar * (water + C * r + D * s) < (C * r + D * s) * weight:
                    weight = water + C * r + D * s
                    sugar = C * r + D * s
    if sugar == 0:
        print("{} 0".format(100 * A))
    else:
        print("{} {}".format(weight, sugar))

    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            density = 100*s/(w+s)
                            memo[a,b,c,d] = density
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    max_concentration = 0
    ans = (100 * A, 0)
    for a in range(0, F + 1, 100 * A):
        for b in range(0, F - a + 1, 100 * B):
            water = a + b
            if water == 0:
                break
            for c in range(0, F - water + 1, C):
                for d in range(0, F - water - c + 1, D):
                    sugar = c + d
                    if sugar > (water // 100) * E:
                        break
                    concentration = (100 * sugar) / (water + sugar)
                    if concentration > max_concentration:
                        max_concentration = concentration
                        ans = (water + sugar, sugar)

    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect
a,b,c,d,e,f = map(int,input().split())
lw = []
ls = []
for i in range((f//100)//b+1):
    for j in range(100):
        if b*i*100+a*j*100 > f:
            break
        lw.append(b*i*100+a*j*100)
for i in range((f//2)//d+1):
    for j in range(3000):
        if (d*i+c*j) > (f*e)/(100+e):
            break
        ls.append(d*i+c*j)
ls.sort()
lw.sort()
n = len(lw)
ans = 0
ansl = [0,0]

for i in range(n):
    w = lw[i]
    t = min(f-w,w/100*e)
    s = ls[bisect.bisect_right(ls,t)-1]
    if (s+w)==0:
        continue
    if 100*s/(s+w) >= ans:
        ans = 100*s/(s+w)
        ansl = [s+w,s]
print(*ansl)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int, open(0).read().split())
ans = [0] * 3
for a in range(F//(100*A)+1):
    for b in range((F-(100*A)*a)//(100*B)+1):
        if a == 0 and b == 0:
            continue
        else:
            m = min(((A*a)+(B*b))*E,F-(100*((A*a)+(B*b))))
            sugar = 0
            for c in range(m//C+1):
                sugar = max(sugar,m-(m-C*c)%D)
                if sugar == m:
                    break
            temp = sugar / (100*((A*a)+(B*b))+sugar)
            if temp > ans[0]:
                ans[0] = temp
                ans[1] = 100 * ((A*a)+(B*b)) + sugar
                ans[2] = sugar
if ans[1] == 0:
    ans[1] = 100 * A
print(ans[1],ans[2])

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
water=[]
suger=[]
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        if 0<100*(i*A+j*B)<=F:
            water.append(100*(i*A+j*B))
        if 100*(i*A+j*B)>F:
            break

for i in range((F*E//(100+E))//C+1):
    for j in range((F*E//(100+E))//D+1):
        if 0<=i*C+j*D<=F*E/(100+E):
            suger.append(i*C+j*D)
        if i*C+j*D>F*E/(100+E):
            break


c=0
w=100*A #初期値に注意！！！！！！
s=0
for i in range(len(water)):
    for j in range(len(suger)):
        if water[i]+suger[j]<=F and water[i]*E/100>=suger[j] and suger[j]/(water[i]+suger[j])>c:
            c=suger[j]/(water[i]+suger[j])
            w=water[i]
            s=suger[j]

print(w+s,s)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

    sugar = sorted(sugar)

    water = set()
    for i in range(F // (100 * A) + 1):
        for j in range(F // (100 * B) + 1):
            w = 100 * A * i + 100 * B * j
            if w <= F:
                water.add(w)
            else:
                break

    water = sorted(water)

    concentration = 0
    ans_water = ans_sugar = 0
    for w in water[1:]:
        s_max = min(F - w, w // 100 * E)
        s = sugar[bisect_right(sugar, s_max) - 1]
        if concentration < 100 * s / (w + s):
            concentration = 100 * s / (w + s)
            ans_water = w
            ans_sugar = s

    if ans_water == 0:
        ans_water = 100 * A

    print(ans_water + ans_sugar, ans_sugar)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

max_s=0
max_w=a
max_conc=0

water_s=set()
sugar_s=set()
for i in range(f//a//100+1):
  aa=a*i
  for j in range(f//b//100+1):
    bb=b*j
    if aa+bb <= f//100:
      water_s.add(aa+bb)
      
for i in range(f//c+1):
  cc=c*i
  for j in range(f//d+1):
    dd=d*j
    if cc+dd <= f:
      sugar_s.add(cc+dd)

for w in water_s:
  for sg in sugar_s:
    if w*100+sg <= f and w*e >= sg and w+sg > 0:
      conc=(100*sg)/(100*w+sg)
      if max_conc < conc:
        max_conc=conc
        max_w=w
        max_s=sg
print(max_w*100+max_s,max_s)

Submission status: Accepted

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

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

def searints(m,n,l):#m<=n
  mask=(1<<l+1)-1
  s=sum([1<<n*i for i in range(1,l//n+1)])&mask
  for i in range(1,l//m+1):
    s=(s+1<<m*i|s) &mask
  return [x for x in range(0,l+1) if ((s+1)>>x)&1==1]

w=searints(100*a,100*b,f)
s=searints(c,d,f)
candidates=[(100*y/(x+y),x+y,y) for x in w for y in s if e*x>=100*y and x*y>0 and x+y<=f]
if candidates:
  print(*max(candidates)[1:])
else:
  print(100*a,0)

Submission status: Accepted

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

# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))

# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))

# max_conc=0から始めると0%の場合を拾えなくなる. あるいは34行目で等号をつけても良い.
max_conc = -1
max_conc_water = -1
max_conc_sugar = -1
for water in water_list:
    for sugar in sugar_list:
        # 水があるか and 溶解度を超えていないか and 容器に入るか
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc > max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)
# print(max_conc)

Submission status: Accepted

Solution code:
# 35行目. >だと1ケース通らずWA, >=だとAC. なんで？？？？？

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

# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))

# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))

max_conc = 0
max_conc_water = 0
max_conc_sugar = 0
for water in water_list:
    for sugar in sugar_list:
        # 水があるか and 溶解度を超えていないか and 容器に入るか
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc >= max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)
# print(max_conc)

Submission status: Accepted

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

# 可能な水の総量
water_list = []
A_max = F // (100 * A)
B_max = F // (100 * B)
for i in range(A_max + 1):
    for j in range(B_max + 1):
        temp = 100 * A * i + 100 * B * j
        if temp <= F:
            water_list.append(temp)
water_list = list(set(water_list))

# 可能な砂糖の総量
sugar_list = []
C_max = F // (C)
D_max = F // (D)
for i in range(C_max + 1):
    for j in range(D_max + 1):
        temp = C * i + D * j
        if temp <= F:
            sugar_list.append(temp)
sugar_list = list(set(sugar_list))

max_conc = 0
max_conc_water = 0
max_conc_sugar = 0
for water in water_list:
    for sugar in sugar_list:
        # 水があるか and 溶解度を超えていないか and 容器に入るか
        if water != 0 and sugar <= ((E * water) / 100) and water + sugar <= F:
            conc = (100 * sugar) / (water + sugar)
            if conc >= max_conc:
                max_conc = conc
                max_conc_water = water
                max_conc_sugar = sugar

print(max_conc_water + max_conc_sugar, max_conc_sugar)
# print(max_conc)

Submission status: Accepted

Solution code:
from copy import deepcopy
import itertools

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

qA = [i // 100 for i in range(0, F + 1, A * 100)]
qB = [i // 100 for i in range(0, F + 1, B * 100)]
qC = [i for i in range(0, F + 1, C)]
qD = [i for i in range(0, F + 1, D)]

W = set(qA + qB)
for i in range(F // min(A, B)):
    nW = deepcopy(W)
    for w in W:
        if (w + A) * 100 <= F:
            nW.add(w + A)
        if (w + B) * 100 <= F:
            nW.add(w + B)

    if len(W) == len(nW):
        break
    W = deepcopy(nW)

W = nW

S = set(qC + qD)
for i in range(F // min(C, D)):
    nS = deepcopy(S)
    for s in S:
        if (s + C) <= F:
            nS.add(s + C)
        if (s + D) <= F:
            nS.add(s + D)

    if len(S) == len(nS):
        break
    S = deepcopy(nS)
S = nS

M = 0
Ms = 0
Mw = A
for w, s in itertools.product(W, S):
    if w != 0 and s <= w * E and s + 100 * w <= F:
        if M < s / (w * 100 + s):
            M = s / (w * 100 + s)
            Ms = s
            Mw = w

print(Ms + Mw * 100)
print(Ms)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
w=set()
for i in range(0,f,100*a):
    for j in range(0,f,100*b):
        if i+j<=f:
            w.add(i+j)
        else:
            break
s=set()
for i in range(0,f,c):
    for j in range(0,f,d):
        if i+j<=f:
            s.add(i+j)
        else:
            break
n=100*a
m=0
l=0
for x in w:
    for t in s:
        if x+t!=0 and x+t<=f and 100*t<=e*x and t/(x+t)>l:
            n=x+t
            m=t
            l=t/(x+t)
print(n,m)

Submission status: Accepted

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

noudo = 0
satou = 0
sato_mizu = 100 * A

for x in range(F//(100*A)+1):
    for y in range(F//(100*B)+1):
        if 100 * (A*x+B*y) > F:
            break

        for z in range(F // C + 1):
            if C * z > (A * x + B * y) * E:
                break

            if 100 * (A * x + B * y) + C * z > F:
                break

            for w in range(F // C + 1):
                if (C*z + D*w + 100 * (A*x+B*y)) == 0:
                    break

                if C*z + D*w > (A * x + B * y)*E:
                    break

                if 100 * (A*x+B*y)+C*z + D*w > F:
                    break

                if noudo < 100* (C*z + D*w)/(C*z + D*w + 100 * (A*x+B*y)):
                    noudo = 100* (C*z + D*w)/(C*z + D*w + 100 * (A*x+B*y))
                    sato_mizu = (C*z + D*w + 100 * (A*x+B*y))
                    satou = C*z + D*w
print(sato_mizu, satou)

Submission status: Accepted

Solution code:
import sys

A, B, C, D, E, F = map(int, sys.stdin.readline().split())

max_a = (F - 1) // (100 * A) + 1
max_b = (F - 1) // (100 * B) + 1

max_rate = 0
ans_water = 0
ans_sugar = 0
for a in range(max_a + 1):
    for b in range(max_b + 1):
        water = 100 * A * a + 100 * B * b
        if water >= F:
            break

        max_sugar = min(F - water, water // 100 * E)
        # print("max_sugar", max_sugar)
        max_c = (max_sugar - 1) // C + 1
        max_d = (max_sugar - 1) // D + 1
        for c in range(max_c + 1):
            for d in range(max_d + 1):
                sugar = C * c + D * d
                if sugar > max_sugar or sugar + water > F:
                    break

                if sugar * (ans_water + ans_sugar) >= ans_sugar * (water + sugar):
                    ans_water = water
                    ans_sugar = sugar

print(ans_water + ans_sugar, ans_sugar)

Submission status: Accepted

Solution code:
import numpy as np


def solve(stdin):
    A, B, C, D, E, F = stdin
    conc = -1
    ans = (1, 2)
    for na in range(F // (100 * A) + 1):
        for nb in range(F // (100 * B) + 1):
            if na == nb == 0:
                continue
            G = F - na * 100 * A - nb * 100 * B
            for nc in range(G // C + 1):
                for nd in range(G // D + 1):
                    W = na * 100 * A + nb * 100 * B + nc * C + nd * D
                    if 0 < W <= F and nc * C + nd * D <= E * (na * A + nb * B):
                        conc2 = 100 * (nc * C + nd * D) / W
                        if conc < conc2 <= 100 * E / (100 + E):
                            ans = (W, nc * C + nd * D)
                            conc = conc2
    return ans


def main():
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    print(*solve(stdin))


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Submission status: Accepted

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


def main(A, B, C, D, E, F):
    conc = -1
    ans = (1, 2)
    for na in range(F // (100 * A) + 1):
        for nb in range(F // (100 * B) + 1):
            if na == nb == 0:
                continue
            G = F - na * 100 * A - nb * 100 * B
            for nc in range(G // C + 1):
                for nd in range(G // D + 1):
                    W = na * 100 * A + nb * 100 * B + nc * C + nd * D
                    if 0 < W <= F and nc * C + nd * D <= E * (na * A + nb * B):
                        conc2 = 100 * (nc * C + nd * D) / W
                        if conc < conc2 <= 100 * E / (100 + E):
                            ans = (W, nc * C + nd * D)
                            conc = conc2
    return ans


print(*main(A, B, C, D, E, F))

Submission status: Accepted

Solution code:
from numba import njit
A, B, C, D, E, F = [int(_) for _ in input().split()]


@njit
def main(A, B, C, D, E, F):
    conc = -1
    ans = (1, 2)
    for na in range(F // (100 * A) + 1):
        for nb in range(F // (100 * B) + 1):
            if na == nb == 0:
                continue
            G = F - na * 100 * A - nb * 100 * B
            for nc in range(G // C + 1):
                for nd in range(G // D + 1):
                    W = na * 100 * A + nb * 100 * B + nc * C + nd * D
                    if 0 < W <= F and nc * C + nd * D <= E * (na * A + nb * B):
                        conc2 = 100 * (nc * C + nd * D) / W
                        if conc < conc2 <= 100 * E / (100 + E):
                            ans = (W, nc * C + nd * D)
                            conc = conc2
    return ans


print(*main(A, B, C, D, E, F))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B, C, D, E, F = MAP()

ans = (-1, 0, 0)
for w1 in range(0, F+1, 100*A):
	for w2 in range(0, F-w1+1, 100*B):
		w = w1+w2
		for s1 in range(0, min(F-w+1, w*E//100+1), C):
			for s2 in range(0, min(F-w-s1+1, w*E//100-s1+1), D):
				s = s1+s2
				a = w+s
				ans = max(ans, (s/a if a != 0 else -1, a, s))

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B, C, D, E, F = MAP()

water = set()

for a in range(F//(100*A)+1):
	for b in range((F-100*a*A)//(100*B)+1):
		water.add(100*(a*A+b*B))

sugar = [0]*(F+1)
sugar[0] = 1
for i in range(1, F+1):
	sugar[i] = 0<(sugar[i-C]*(0<i) + sugar[i-D]*(0<i))

sugar_acc = [0]*(F+1)
tmp = 0
for i in range(F//2+1):
	if sugar[i] == 1:
		tmp = i
	sugar_acc[i] = tmp

#print(water)
#print(sugar_acc)

ans = 0
den = 0
water_ans = 0
sugar_ans = 0
water = sorted(list(water))

for water_tmp in water[1:]:
	t = min(E*water_tmp//100, F-water_tmp)
	sugar_tmp = sugar_acc[t]
	den_tmp = sugar_tmp/(sugar_tmp+water_tmp)

	if den <= den_tmp:
		den = den_tmp
		water_ans = water_tmp
		sugar_ans = sugar_tmp

print(water_ans+sugar_ans, sugar_ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B, C, D, E, F = MAP()

water = set()

for a in range(F//(100*A)+1):
	for b in range((F-100*a*A)//(100*B)+1):
		water.add(100*(a*A+b*B))

sugar = [0]*(F+1)
sugar[0] = 1
for i in range(1, F+1):
	sugar[i] = 0<(sugar[i-C]*(0<i) + sugar[i-D]*(0<i))

sugar_acc = [0]*(F+1)
tmp = 0
for i in range(F//2+1):
	if sugar[i] == 1:
		tmp = i
	sugar_acc[i] = tmp

#print(water)
#print(sugar_acc)

ans = 0
den = 0
water_ans = 0
sugar_ans = 0
water = sorted(list(water))

for water_tmp in water[1:]:
	t = min(E*water_tmp//100, F-water_tmp)
	sugar_tmp = sugar_acc[t]
	if F < sugar_tmp + water_tmp:
		continue
	den_tmp = sugar_tmp/(sugar_tmp+water_tmp)

	if den <= den_tmp:
		den = den_tmp
		water_ans = water_tmp
		sugar_ans = sugar_tmp

print(water_ans+sugar_ans, sugar_ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

A, B, C, D, E, F = MAP()

water = set()

for a in range(F//(100*A)+1):
	for b in range((F-100*a*A)//(100*B)+1):
		water.add(100*(a*A+b*B))

sugar = [0]*(F+1)
sugar[0] = 1
for i in range(1, F+1):
	sugar[i] = 0<(sugar[i-C]*(0<i) + sugar[i-D]*(0<i))
#print(sugar)
"""
f = F//2
sugar = [0]*(F+1)
for c in range(f//C+1):
	for d in range((f-c*C)//D+1):
		sugar[c*C+d*D] = 1
print(sugar)
"""
sugar_acc = [0]*(F+1)
tmp = 0
for i in range(F//2+1):
	if sugar[i] == 1:
		tmp = i
	sugar_acc[i] = tmp

#print(water)
#print(sugar_acc)

ans = 0
den = 0
water_ans = 0
sugar_ans = 0
water = sorted(list(water))

for water_tmp in water[1:]:
	if E == 100:
		t = min(water_tmp, F-water_tmp)
	else:
		t = min(E*water_tmp//100, F-water_tmp)

	sugar_tmp = sugar_acc[t]
	if F < sugar_tmp + water_tmp:
		continue

	if sugar_tmp == 0:
		den_tmp = 0
	else:
		den_tmp = sugar_tmp/(sugar_tmp+water_tmp)

	#print(water_tmp, sugar_tmp, den_tmp, E*water_tmp//(100-E), F-water_tmp, t)
	if den <= den_tmp:
		den = den_tmp
		water_ans = water_tmp
		sugar_ans = sugar_tmp

print(water_ans+sugar_ans, sugar_ans)