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())
W = []
S = []
for a in range(F//100+1):
    for b in range(F//100+1):
        w = A*a+B*b
        if 1 < 100*w < F:
            W.append(w)
            slist = []
            for c in range((F-100*w)//C+1):
                for d in range((F-100*w)//D+1):
                    if C*c+D*d <= F-100*w:
                        slist.append(C*c+D*d)
            S.append(slist)
maxs = [100*A,0]
rel = 0
for w in range(len(W)):
    for s in range(len(S[w])-1,-1,-1):
        if E*W[w] >= S[w][s]:
            if rel < 100*S[w][s]/(W[w]+S[w][s]):
                maxs = [100*W[w]+S[w][s],S[w][s]]
                rel = 100*S[w][s]/(W[w]+S[w][s])
print(*maxs)

Submission status: Accepted

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

# x = 100A, 100B  , y = C, Dが与えられたとき
# x + y <= F を満たす(x, y)の組み合わせを求める。
# X = []
# Y = []
# print(F // 100)
# for x in range(1, (F // 100) + 1):
#     for y in range(1, F - x + 1):
#         if (100*x % A == 0) or (100*x % B == 0) and (y % C == 0 or y % D == 0) and (y/(100+y)) <= (E/(100+E)):
#             X.append(100*x)
#             Y.append(y)
# (100y/(100+y) <= (100E/(100+E))が成り立つときtrue
# for i in range(len(X)):
#     print(X[i] + Y[i], Y[i])
X = []
Y = []
Den = []
for i in range(31):
    for j in range(31):
        x = 100*A*i + 100*B*j
        for l in range(101):
            for m in range(101):
                y = C*l + D*m
                if 0 < x + y <= F and (y/(x+y)) <= (E/(100+E)):
                    X.append(x)
                    Y.append(y)
                    density = y/(x+y)
                    Den.append(density)
max_d = 0
max_i = 0
for i in range(len(Den)):
    if Den[i] > max_d:
        max_d = Den[i]
        max_i = i

print(X[max_i]+Y[max_i], Y[max_i])

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
#print(dp1)
#print(dp2)
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:

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

density = -1
ans = (0, 0)

for a in range(31):
  for b in range(31):
    for c in range(101):
      for d in range(101):
        water = 100*a*A + 100*b*B
        suger = c*C + d*D
         
        if water + suger > F or water == 0:
          break

        if (water / 100) * E >= suger:
        
          tmp = (100 * suger)  / (water + suger)

          if tmp > density:
            density = tmp
            ans = (water+suger, suger)

print(*ans)

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

Submission status: Accepted

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

ans = [0,0]
per = -1

for w in range(1,f+1):
    wt = 0
    for b in range(0,w+1,B):
        if (w-b)%A == 0:
            wt = 1
            break
    if wt == 0:
        continue
    water = w*100

    for s in range(min(w*E,F-water),-1,-1):
        st = 0
        for d in range(0,s+1,D):
            if (s-d)%C == 0:
                st = 1
                break
        if st == 1:
            break

    if s/(s+water) > per:
        ans = [s+water,s]
        per = s/(s+water)

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

Submission status: Accepted

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

ans = [0,0]
per = -1

for w in range(1,f+1):
    wt = 0
    for b in range(0,w+1,B):
        if (w-b)%A == 0:
            wt = 1
            break
    if wt == 0:
        continue

    water = w*100

    for s in range(min(w*E,F-water),-1,-1):
        st = 0
        for d in range(0,s+1,D):
            if (s-d)%C == 0:
                st = 1
                break
        if st == 1:
            break

    if s/(s+water) > per:
        ans = [s+water,s]
        per = s/(s+water)

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

Submission status: Accepted

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

ans = [0,0]
per = -1
#水の量を100g単位ずつ全探索
for w in range(1,f+1):
    #そのような水の取り方があるか確認
    wt = 0
    for b in range(0,w+1,B):
        if (w-b)%A == 0:
            wt = 1
            break
    if wt == 0:
        continue

    water = w*100
    st = 0
    #砂糖として考えられる量を大きい順に0gまでに全探索
    for s in range(min(w*E,F-water),-1,-1):
        st = 0
        for d in range(0,s+1,D):
            if (s-d)%C == 0:
                st = 1
                break
        if st == 1:
            break

    if s/(s+water) > per:
        ans = [s+water,s]
        per = s/(s+water)

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

Submission status: Accepted

Solution code:

A,B,C,D,E,F = map(int,input().split(' '))
ans = [0,0]
r = 0
for i in range(F//A+1):
    for j in range(F//B+1):
        if (i == 0 and j == 0) or  100*(A*i+B*j) > F:
            break
        for k in range(F//C+1):
            for l in range(F//D+1):
                tmp = 100*A*i+100*B*j+C*k+D*l
                r_tmp = 100*(C*k+D*l)/tmp
                if tmp > F:
                    break
                if r <= r_tmp and 100*(C*k+D*l)/(100*(A*i+B*j)) <=E:
                    r = r_tmp
                    ans = [tmp,C*k+D*l]
print(ans[0],ans[1])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = tuple(map(int, input().split()))
max_con = 0
res = (100 * A, 0)
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        if i == 0 and j == 0:
            continue
        wat = (A * i + B * j)
        x = 100 * wat
        if F < x:
            continue
        for k in range(wat * E // C + 1):
            for l in range(wat * E // D + 1):
                y = C * k + D * l
                if wat * E < y:
                    continue
                total = x + y
                if F < total:
                    continue
                if max_con < y / total:
                    max_con = y / total
                    res = (total, y)
                    # print(x + y, y)
print(*res)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
noudomax=0
weight=0
weightmax=100*a
sugarmax=0
i=0
while True:
    weight=a*100*i
    if weight>f:
        break
    j=0
    while True:
        if i==j==0:
            j+=1
            continue
        weight=a*100*i+b*100*j
        if weight>f:
            break
        k=0
        while True:
            weight=a*100*i+b*100*j+c*k
            if weight>f:
                break
            l=0
            while True:
                weight=a*100*i+b*100*j+c*k+d*l
                sugar=c*k+d*l
                if weight>f:
                    break
                noudo=100*sugar/weight
                if noudomax<noudo<=100*e/(e+100):
                    #print(noudo,i,j,k,l)
                    weightmax=weight
                    sugarmax=sugar
                    noudomax=noudo
                l+=1
            k+=1
        j+=1
    i+=1

print(weightmax,sugarmax)

Submission status: Accepted

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

sw = 100 * A
sugar = 0
percent = 0
for k in range(F // (100 * A) + 1):
    for l in range(F // (100 * B) + 1):
        if k == 0 and l == 0:
            continue
        tmp = A * k + B * l
        if 100 * tmp > F:
            continue
        for i in range(tmp*E//C + 1):
            for j in range(tmp*E//D + 1):
                tmp2 = i * C + j * D
                if 100 * tmp + tmp2 > F:
                    continue
                if tmp2 > tmp * E:
                    continue
                t = 100 * tmp2 / (100 * tmp + tmp2)
                if t > percent:
                    percent = t
                    sw = 100 * tmp + tmp2
                    sugar = tmp2

print(sw, sugar)

Submission status: Accepted

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

ans, cont = [0]*2, 0

for i in range(f//100+1):
    if i%a == 0 or i%b == 0:
        water = i*100
        x = min(f-water, i*e)

        suger = 0

        for j in range(x//c+1):
            s3 = j*c
            suger = max(suger, s3+((x-s3)//d)*d)

        if water != 0:
            if cont <= (100*suger) / (water+suger):
                ans = [water, suger]
                cont = (100*suger) / (water+suger)

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

Submission status: Accepted

Solution code:

def ansloop(wcnt1, fcnt, n):
    wcnt1 *= n
    fcnt *= n
    tans = 0
    while wcnt1 >= 0:
        tmpans = wcnt1 * inlst[2]
        if tmpans <= cnt1 * n:
            tmp = tmpans
            for i in range(fcnt):
                tmp += inlst[3]
                if tmp <= cnt1 * n:
                    tmpans = tmp
                else:
                    break
            tans = max(tans, tmpans)
        wcnt1 -= 1
    return tans

inlst = list(map(int, input().split()))
ans1 = 0
cnt1 = inlst[0] * inlst[4]
if cnt1 + (inlst[0] * 100) > inlst[-1]:
    cnt1 = inlst[-1] - (inlst[0] * 100)
wcnt1 = (cnt1 // inlst[2] + 1)
fcnt = wcnt1
roopcnt = inlst[-1] // (cnt1 + 100 * inlst[0])

index = 1
for i in range(1, roopcnt + 1):
    tmp = ansloop(wcnt1, fcnt, i)
    if (100 * ans1) / (index * 100 * inlst[0] + ans1) < (100 * tmp) / (i * 100 * inlst[0] + tmp):
        ans1 = tmp
        index = i
print(100 * inlst[0] * index + ans1, ans1)

Submission status: Accepted

Solution code:
inlst = list(map(int, input().split()))
ans1 = 0
ans2 = 0
cnt1 = inlst[0] * inlst[4]
if cnt1 + (inlst[0] * 100) > inlst[-1]:
    cnt1 = inlst[-1] - (inlst[0] * 100)
wcnt1 = (cnt1 // inlst[2] + 1)
fcnt = wcnt1
roopcnt = inlst[-1] // (cnt1 + 100 * inlst[0])
def ansloop(wcnt1, fcnt, n):
    wcnt1 *= n
    fcnt *= n
    tans = 0
    while wcnt1 >= 0:
        tmpans = wcnt1 * inlst[2]
        if tmpans <= cnt1 * n:
            tmp = tmpans
            for i in range(fcnt):
                tmp += inlst[3]
                if tmp <= cnt1 * n:
                    tmpans = tmp
                else:
                    break
            tans = max(tans, tmpans)
        wcnt1 -= 1
    return tans
index = 1
for i in range(1, roopcnt + 1):
    tmp = ansloop(wcnt1, fcnt, i)
    if (100 * ans1) / (index * 100 * inlst[0] + ans1) < (100 * tmp) / (i * 100 * inlst[0] + tmp):
        ans1 = tmp
        index = i
print(100 * inlst[0] * index + ans1, ans1)

Submission status: Accepted

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

watars = []
import math
for i in range(int(math.floor(F/ (A*100)))+1):
    rest = F - A * 100 * i
    for j in range(int(math.floor(rest/ (B*100)))+1):
        watars.append(A*100*i + B*100*j)

salts = []
lim_salt = int(F * E // 100)
for i in range(int(math.floor(lim_salt/ C))+1):
    rest = lim_salt - C * i
    for j in range(int(math.floor(rest/ D))+1):
        salts.append(C*i + D*j)

watars = set(watars)
salts = set(salts)

# print(len(watars), len(salts))

max_ratio = 0
ans = [0, 0]
for watar in watars:
    if watar == 0:
        continue

    for salt in salts:
        amount = watar + salt
        ratio = salt / amount
        if amount <= F and salt <= watar * E / 100:
            if ratio > max_ratio:
                max_ratio = ratio
                ans = [watar, salt]

if max_ratio == 0:
    water = min([water for water in watars
                 if 0 < water <= F])
    print(water, 0)

else:
    print(sum(ans), ans[1])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
Swater, sugar, percent = 100*A, 0, 0
for k in range(F//(100*A) + 1):
  for l in range(F//(100*B) + 1):
    if k == 0 and l == 0:
      continue
    M = k*A + l*B
    if 100 * M > F:
      continue
    for x in range(M*E//C + 1):
      for y in range(M*E//D + 1):
        S = C*x + D*y
        if 100*M+S > F:
          continue
        if S > M*E:
          continue
        t = 100*S / (100*M+S)
        if t > percent:
          percent = t
          Swater = 100*M+S
          sugar = S
print(Swater, sugar)

Submission status: Accepted

Solution code:
import sys


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

    # sum(ABCD) < F
    # sum(AB) * E <= sum(CD)

    max_dense = 0
    result = (A * 100, 0)
    AB = sorted(list(set([a for a in range(0, int(F / 100) + 1, A)] + [b for b in range(0, int(F / 100) + 1, B)])))
    for water in AB:
        if water == 0:
            continue
        c = 0
        while water * 100 + c <= F and c <= water * E:
            d = 0
            while water * 100 + c + d <= F and c + d <= water * E:
                sugar = c + d
                total = water * 100 + sugar
                dense = 100 * sugar / total
                if dense > max_dense:
                    # print("{} {} {} {} : {}".format(total, water * 100, c, d, dense))
                    max_dense = dense
                    result = (total, sugar)
                d += D
            c += C

    return "{} {}".format(result[0], result[1])


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
possible_x = set()
possible_y = set()
for i in range(32):
    for j in range(32):
        value = i*100*A+j*100*B
        if value <= F:
            possible_x.add(value)
for i in range(3001//C+10):
    for j in range(3001//D+10):
        value = C*i+D*j
        if value <= F:
            possible_y.add(value)
max_density = 0
max_water = 0
max_sugar = 0
for x in possible_x:
    for y in possible_y:
        if x+y > F:
            pass
        elif E*x/100 < y:
            pass
        else:
            if x+y == 0:
                pass
            elif (100*y)/(x+y) >= max_density:
                max_density = (100*y)/(x+y)
                max_water = x
                max_sugar = y
print(max_water+max_sugar,max_sugar)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()

  ans_n=-inf
  ans_pair=[0,0]
  xf=100*e/(100+e)
  for i in range(31):
    for j in range(31):
      for k in range(101):
        for l in range(101):
          xa=100*a*i+100*b*j
          xb=c*k+d*l

          # print(xa,xb)
          if xa+xb>f:
            break

          if xa+xb==0:
            continue

          xc=100*xb/(xa+xb)
          if xc>xf:
            continue

          if ans_n<xc:
            ans_n=xc
            ans_pair=[xa+xb,xb]

  return str(ans_pair[0])+' '+str(ans_pair[1])

# main()
print(main())

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
ans0 = 100*A
ans1 = 0

for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if sugar*ans0>ans1*(water+sugar):
                    ans0 = water+sugar
                    ans1 = sugar

print(ans0, ans1)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1

for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar

print(ans0, ans1)

Submission status: Accepted

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


# 水が入る量をリストアップ
W = set()
for a in range(0, F+1, A*100):
  for b in range(0, F+1, B*100):
    w = a+b
    if w==0 or w>F:
      continue
    W.add(w)
    
# 砂糖が入る量をリストアップ
Suger = set()
for c in range(0, F+1, C):
  for d in range(0, F+1, D):
    s = c+d
    if s>F:
      continue
    Suger.add(s)
    
d_max = -1
ans = None
for w in W:
  for s in Suger:
    # 砂糖が溶けない or ビーカーの容量を超えたらcontinue
    if w*E//100 < s or w+s > F:
      continue
    d = 100*s / (w+s) # 濃度
    if d > d_max:
      d_max = d
      ans = (w+s, s)
print(*ans)

Submission status: Accepted

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

water_list = []

def nearest_suger(suger1, suger2, rest_amount, water):
    max_sum = 0
    target = min(int(water * (e / 100)), rest_amount)
    for i in range((target//suger1)+1):
        for j in range((target//suger2)+1):
            sum = i * suger1 + j* suger2
            if sum > target:
                break
            if max_sum < sum:
                max_sum = sum
    return max_sum



for i in range(30):
    if 100*a*i <= f:
        water_list.append(100*a*i)
    if 100*b*i <= f:
        water_list.append(100*b*i)

water_list = set(water_list)
water_list = list(water_list)
water_list.sort()
water_list.pop(0)

max_percent = 0

for i in water_list:
    suger = nearest_suger(c, d, f-i, i)
    percent = suger / (i + suger)
    if percent == (e / 100):
        print(suger+i, suger)
        exit()
    elif percent > (e / 100):
        continue
    elif percent >= max_percent:
        max_percent = percent
        suger_ans = suger
        water_ans = i

print(water_ans + suger_ans, suger_ans)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans,con = [0]*2, 0
for i in range(f//100+1):
    #操作1,2はどちらか片方だけで良い.両方やると濃度が下がる?
    if i%a==0 or i%b==0:
        w=i*100 #水の量を基準にして, 砂糖の量を決めていく.
        x=min(f-w, i*e) # 残り加えられる砂糖の量
        s=0
        
        # 砂糖を操作3で加える
        for j in range(x//c+1):
            s3 = j*c
            #操作4も織り交ぜて, 砂糖の最大値を見つける.
            s=max(s, s3+((x-s3)//d)*d)
            
        if w!=0: #ゼロ割回避
            if con<=(100*s)/(w+s):
                ans = [w,s]
                con = (100*s)/(w+s)
print(sum(ans), ans[1])

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
dp = [-1]*(F+1)
dp[0] = 0

amount, ans = 1, 0
for i in range(1, F+1):
    if i < A*100:
        continue

    if i >= A*100 and dp[i-A*100] != -1:
        dp[i] = max(dp[i], dp[i-A*100])
    if i >= B*100 and dp[i-B*100] != -1:
        dp[i] = max(dp[i], dp[i-B*100])

    if i >= C and dp[i-C] != -1 and (dp[i-C]+C)/(i-C-dp[i-C]) <= E/100:
        dp[i] = max(dp[i], dp[i-C]+C)
    if i >= D and dp[i-D] != -1 and (dp[i-D]+D)/(i-D-dp[i-D]) <= E/100:
        dp[i] = max(dp[i], dp[i-D]+D)

    if ans/amount <= dp[i]/i:
        amount = i
        ans = dp[i]
print(amount, ans)

Submission status: Accepted

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 can_make(num, a, b):
    while num >= 0:
        if num % a == 0 or num % b == 0:
            return True
        num -= a
    return False

def main():
    A, B, C, D, E, F = LI()
    if A > B:
        A, B = B, A
    if C > D:
        C, D = D, C
    max_perc = -1
    max_sugar = -1
    max_water = -1
    for unit in range(A, 31):
        water = unit * 100
        for sugar in range(min(F - water, unit*E)+1):
            # if water + sugar == 2634 and sugar == 934:
            #     import pdb
            #     pdb.set_trace()
            if water + sugar > F:
                continue
            if 100*sugar/(water+sugar) > E:
                continue
            if can_make(sugar, C, D) and can_make(water, 100*A, 100*B):
                perc = sugar/(sugar + water)
                if perc >= max_perc:
                    max_perc = perc
                    max_sugar = sugar
                    max_water = water
    print(max_water + max_sugar, max_sugar)

main()

Submission status: Accepted

Solution code:
a, b, c, d, e, f=map(int, input().split())
def g(x, y):
  if y==0:
    return 0
  else:
    return x/y
  
maxnodo=g(e, 100+e)
a*=100
b*=100

candnodo=0
out=[a, 0]
q_max=f//b
for q in range(q_max, -1, -1):
  p_max=(f-b*q)//a
  for p in range(p_max, -1, -1):
    s_max=(f-(a*p+b*q))//d
    while s_max>0 and g(d*s_max, a*p+b*q+d*s_max)>maxnodo:
      s_max-=1
      
    for s in range(s_max, -1, -1):
      r=(f-(a*p+b*q+d*s))//c
      while r>0 and g(c*r+d*s, a*p+b*q+c*r+d*s)>maxnodo:
        r-=1
        
      if g(c*r+d*s, a*p+b*q+c*r+d*s)>candnodo:
        candnodo=g(c*r+d*s, a*p+b*q+c*r+d*s)
        out=[a*p+b*q+c*r+d*s, c*r+d*s]
        temp=[p, q, r, s]
print(*out)

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,C,D,E,F = MI()
    A*=100
    B*=100
    water = []
    can = [False]*3001
    can[0] = True
    for i in range(3001-A):
        if can[i]:
            can[i+A] = True
    for i in range(3001-B):
        if can[i]:
            can[i+B] = True
    for i in range(1,3001):
        if can[i]:
            water.append(i)

    can = [False]*3001
    can[0] = True
    for i in range(3001-C):
        if can[i]:
            can[i+C] = True
    for i in range(3001-D):
        if can[i]:
            can[i+D] = True
    
    suger = []
    for i in range(1,3001):
        if can[i]:
            suger.append(i)
    
    # print(water)
    # print(suger)

    ans = 0
    ans_water = A
    ans_suger = 0
    for w in water:
        want = min(F-w, (w//100)*E)
        idx = bisect_right(suger, want)
        if idx:
            s = suger[idx-1]
            if ans < s/(w+s):
                ans = s/(w+s)
                ans_water=w
                ans_suger=s
                
    print(ans_water+ans_suger,ans_suger)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,c,d,e,f = LI()
    ans = 0
    p = [100*a,0]
    n = 31
    for x in range(n):
        A = a*x
        for y in range(n):
            B = b*y
            s = A+B
            r = min(f-100*s,s*e)
            if r > 0:
                for z in range(r+1):
                    C = c*z
                    rest = r-C
                    if rest < 0:
                        break
                    w = rest//d
                    D = d*w
                    res = (C+D)/(100*s+C+D)
                    if ans < res:
                        ans = res
                        p[0] = 100*s+C+D
                        p[1] = C+D
    print(*p)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

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

SIZE = 3001
W = [0] * SIZE
S = [0] * SIZE

W[A * 100] = 1
W[B * 100] = 1
S[0] = 1

for i in range(SIZE):
  if W[i]:
    if i + A * 100 < SIZE:
      W[i + A * 100] = 1
    if i + B * 100 < SIZE:
      W[i + B * 100] = 1
  if S[i]:
    if i + C < SIZE:
      S[i + C] = 1
    if i + D < SIZE:
      S[i + D] = 1
  
water = []
sugar = []
for i in range(SIZE):
  if W[i] and i <= F:
    water.append(i)
  if S[i] and i <= F:
    sugar.append(i)
#print("water:", water)
#print("sugar:", sugar)

max_p = -1
wss = (0, 0)
for w in water:
  for s in sugar:
    p = s / (s + w) * 100
    if w + s <= F and p <= E / (100 + E) * 100:
      if max_p < p:
        max_p = p
        wss = (w + s, s)
print(*wss)

Submission status: Accepted

Solution code:
from fractions import Fraction
from collections import deque
import math

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

# 作りうる水の量を洗い出す
waters = set()
waters.add(100*A)
if 200*B <= F:
    waters.add(200*B)
q = deque([100*A, 200*B])

while q:
    w = q.popleft()
    # 容器に入れられる量より多いならパス
    if w > F: continue
    for n in [100*A, 200*B]:
        if w + n <= F:
            waters.add(w + n)
            q.append(w + n)

waters = list(waters)
waters.sort()



# 最大濃度
max_conc = -1
# 最大濃度の時の水と砂糖
total = -1
sugar = -1

# それぞれの水量についてなるべく多く砂糖を入れてみる
for w in waters:
    # 砂糖の解けることができる量
    limit = math.floor(w * Fraction(E,100))
    # 全体でFまでしか入らないので、F-wとlimitの小さいほうまでしか追加できない
    limit = min(limit, F - w)
    # Cをi回、Dをj回追加する
    max_sugar = 0
    for i in range(limit // C + 1):
        tmp = C * i + ((limit - C*i) // D) * D
        
        max_sugar = max(max_sugar, tmp)
    if max_conc < Fraction(max_sugar, (w+max_sugar)):
        max_conc = Fraction(max_sugar, (w+max_sugar))
        total = w+max_sugar
        sugar = max_sugar

print(total, sugar)