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

MAX_SUGER = E*F/(E+100)


water = [min(A,B)*100,max(A,B)*100]
for i in range(1,31):
    for j in range(1,31):
        water.append(100*A*i+100*B*j)
water = sorted(list(set(water)))

suger = []
for i in range(101):
    for j in range(101):
        if C*i + D*j <= MAX_SUGER:
            suger.append(C*i+D*j)
suger = sorted(list(set(suger)))

ans = []
for s in suger:
    min_water = 100*s/E
    for w in water:
        if w >= min_water:
            ans.append([s/(w+s),w+s,s])
            break
ans.sort(reverse=True)

for c,w,s in ans:
    if w <= F:
        print(w,s)
        break

Submission status: Accepted

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

MAX_SUGER = E*F/(E+100)


water = [min(A,B)*100,max(A,B)*100]
for i in range(1,300):
    for j in range(1,300):
        water.append(100*A*i+100*B*j)
water = sorted(list(set(water)))

suger = []
for i in range(1000):
    for j in range(1000):
        if C*i + D*j <= MAX_SUGER:
            suger.append(C*i+D*j)
suger = sorted(list(set(suger)))

ans = []
for s in suger:
    min_water = 100*s/E
    for w in water:
        if w >= min_water:
            ans.append([s/(w+s),w+s,s])
            break
ans.sort(reverse=True)
for c,w,s in ans:
    if w <= F:
        print(w,s)
        break

Submission status: Accepted

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

rmax=0
for a100 in range(0,f+1,100*a):
   for b100 in range(0,f-a100+1,100*b):
#   for b100 in range(0,f+1,100*b):
        if a100+b100>0:
            fcd=f-a100-b100
            for ci in range(0,fcd+1,c):
                for di in range(0,fcd+1,d):
                    if a100+b100+ci+di <=f:
                        if (a100+b100)/100*e>=ci+di:
                            if rmax<(ci+di)/(a100+b100):
                                rmax=(ci+di)/(a100+b100)
                                rab=a100+b100+ci+di
                                rcd=ci+di
if rmax>0:
    print(rab,rcd)
else:
    print(100*a,0)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

dp = [-1] * (F + 1)
dp[0] = 0

cnt = 1
for i in range(F + 1):
    if dp[i] >= 0 and i + A * 100 <= F:
        dp[i + A * 100] = max(dp[i + A * 100], dp[i])
    if dp[i] >= 0 and i + B * 100 <= F:
        dp[i + B * 100] = max(dp[i + B * 100], dp[i])
    if dp[i] >= 0 and i + C <= F and (dp[i] + C) * (100 + E) <= (i + C) * E:
        dp[i + C] = max(dp[i + C], dp[i] + C)
    if dp[i] >= 0 and i + D <= F and (dp[i] + D) * (100 + E) <= (i + D) * E:
        dp[i + D] = max(dp[i + D], dp[i] + D)

x, y = A * 100, 0
for i in range(F + 1):
    if x <= 0 or x * dp[i] > y * i:
        x, y = i, dp[i]

print(x, y)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
xas = [i *100*a for i in range(f // a // 100 + 1)]
xbs = [i *100*b for i in range(f // b // 100 + 1)]
xs = {(i+j) for i in xas for j in xbs if i+j <= f}
yc = [i*c for i in range(f//c+1)]
yd = [i*d for i in range(f//d+1)]
ys = {(i+j) for i in yc for j in yd if i + j <= f}
x, y, m = 0, 0, 0
for i in xas:
    for j in ys:
        if i + j == 0:
            continue
        if j / (i+j) >= m and i+ j <= f and j / (i+j) <= e/(100+e):
            x = i
            y = j
            m = y / (x + y)
print(x+y, y)

Submission status: Accepted

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

for i in range(31):
    for j in range(31):
        w = 100 * (a * i + b * j)
        if w > f:
            continue
        water_set.add(w)

for i in range(3001):
    for j in range(3001):
        s = c * i + d * j
        if s > f:
            continue
        sugar_set.add(s)

concentration_lim = e / (100 + e)
concentration = -1
ans_w = 0
ans_s = 0
for s in sugar_set:
    for w in water_set:
        total = s + w
        if total == 0:
            continue
        x = s / total
        if total <= f and x <= concentration_lim and x > concentration:
            concentration = x
            ans_w = total
            ans_s = s

print(ans_w, ans_s)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math

[A, B, C, D, E, F] = list(map(int, stdin.readline().rstrip().split()))

## F
# F >= 100 * A * a + 100 * B * b + C * c + D * d

## E
# C * c + D * d <= (100 * A * a + 100 * B * b) * E / 100
# 100 * (C * c + D * d) <= (100 * A * a + 100 * B * b) * E
# 100 * (C * c + D * d) / (100 * A * a + 100 * B * b) <= E


maximum_ratio = 0
max_a = 0
max_b = 0
max_c = 0
max_d = 0

for a in range(F // (100 * A) + 1):
    for b in range(F // (100 * B) + 1):
        for c in range(F // 2 // C + 1):
            for d in range(F // 2 // D + 1):
                if 100 * A * a + 100 * B * b + C * c + D * d <= F:
                    if 0 == (100 * A * a + 100 * B * b):
                        continue

                    sugar_ratio = 100 * (C * c + D * d) / (100 * A * a + 100 * B * b)
                    if E >= sugar_ratio and maximum_ratio <= sugar_ratio:
                        maximum_ratio = sugar_ratio
                        max_a = a
                        max_b = b
                        max_c = c
                        max_d = d
                else:
                    break

print("%d %d" % (100 * A * max_a + 100 * B * max_b + C * max_c + D * max_d, C * max_c + D * max_d))

Submission status: Accepted

Solution code:
def main():
    from collections import deque
    from itertools import product

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

    water_a = []

    i = 0
    while i * a * 100 <= f:
        water_a.append(i * a * 100)
        i += 1

    water = []
    for w in water_a:
        i = 0
        while i * b * 100 + w <= f:
            water.append(i * b * 100 + w)
            i += 1

    sugar_c = []
    i = 0
    while i * c <= f:
        sugar_c.append(i * c)
        i += 1

    sugar = []
    for s in sugar_c:
        i = 0
        while i * d + s <= f:
            sugar.append(i * d + s)
            i += 1

    conc = -1
    ans = None
    for w, s in product(water, sugar):
        if w + s == 0: continue
        if w + s > f: continue
        if s > w // 100 * e: continue
        t_conc = 100 * s / (w + s)
        if t_conc > conc:
            conc = t_conc
            ans = w + s, s
    print(*ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()

Submission status: Accepted

Solution code:
def resolve():
    A, B, C, D, E, F = list(map(int, input().split()))
    target = 100*E/(100+E)
    result_con = -float("inf")
    result_all = 0
    result_suger = 0
    for i in range(31):
        for j in range(31):
            for k in range(101):
                for l in range(101):
                    total = 100*A*i + 100*B*j + C*k + D*l
                    suger = C*k + D*l
                    if total == 0:
                        continue
                    if total - suger == 0:
                        break
                    if total > F:
                        break
                    con = 100*suger/total
                    if con > target:
                        break
                    if result_con < con:
                        result_con = con
                        result_all = total
                        result_suger = suger
    print("{} {}".format(result_all, result_suger))


if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc074/tasks/arc083_a
# 要復習
A, B, C, D, E, F = read_ints()


# Aを何回を行うか Bを何回行うかは全探索できる #30通り*30通り(たかだか)
satou_candi = set()
for c, d in product(range(3001), repeat=2):
    if c * C + d * D > F:
        continue
    satou_candi.add(c * C + d * D)

water_candi = set()
for a, b in product(range(31), repeat=2):
    if 100 * (A * a + B * b) > F:
        continue
    water_candi.add((A * a + B * b) * 100)

satou_candi = sorted(satou_candi)  # この時点で最大3000通りしか無い
water_candi = sorted(water_candi)
# print(satou_candi)
# print(water_candi)

ans_satou = 0
ans_total = A * 100
for water in water_candi[1:]:
    for satou in satou_candi:
        if satou + water > F:
            continue
        max_satou = E * water // 100  # 100lあたり
        if satou > max_satou:
            continue
        if ans_satou / ans_total < satou / (satou + water):
            ans_satou = satou
            ans_total = water + satou

# for water in water_candi[1:]:
#     max_satou = E * water // 100  # 100lあたり
#     idx = bisect_right(satou_candi, max_satou) - 1  # -1にはならないはず [0]→0なので
#     satou = satou_candi[idx]
#     # print(water, satou, max_satou)
#     if satou + water > F:
#         continue
#     if ans_satou / ans_total < satou / (satou + water):
#         ans_satou = satou
#         ans_total = water + satou

print(ans_total, ans_satou)

Submission status: Accepted

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

water_g=[]
for i in range(f//100+1):
  for j in range(f//100+1):
#    print(i,j)
    w=100*a*i + 100*b*j
    if w<=f:
      water_g.append(w)
    else:
      break
water_g=sorted(list(set(water_g)),reverse=True)

sugar_g=[]
for i in range(f*e//100):
  for j in range(f*e//100):
    s=c*i + d*j
    if s<=f:
      sugar_g.append(s)
    else:
      break
sugar_g=sorted(list(set(sugar_g)),reverse=True)

#print(water_g, sugar_g)

ans_water=100*a
ans_sugar=0
for water in water_g:
  if water==0:
    break
  for sugar in sugar_g:
    if water+sugar<=f and sugar/water<=e/100:
      if sugar/(sugar+water)>ans_sugar/(ans_sugar+ans_water):
        ans_water=water
        ans_sugar=sugar
print(ans_water+ans_sugar,ans_sugar)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    A, B, C, D, E, F = map(int, input().split())
    waters = set()
    for i in range(0, F, A):
        for j in range(0, F, B):
            ij = i * 100 + j * 100
            if ij > F:
                break
            waters.add(ij)
    sugers = set()
    for i in range(0, F, C):
        for j in range(0, F, D):
            ij = i + j
            if ij > F:
                break
            sugers.add(ij)
    ans_water = 0
    ans_suger = 0
    ans = 0
    for water in waters:
        for suger in sugers:
            if water + suger == 0:
                continue
            if water + suger > F:
                continue
            if 100 * suger > E * water:
                continue
            if 100 * suger / (water + suger) > ans:
                ans = 100 * suger / (water + suger)
                ans_water = water
                ans_suger = suger
    if ans_suger == 0:
        if A * 100 <= F:
            print(A*100, 0)
        elif B * 100 <= F:
            print(B*100, 0)
        else:
            print(0, 0)
    else:
        print(ans_water+ans_suger, ans_suger)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def total_check(sugar, water, lim):
    if sugar + water <= lim:
        return True
    else:
        return False


def concentration(sugar, water, lim_sugar):
    if sugar / (sugar + water) <= lim_sugar / (lim_sugar + 100):
        return True
    else:
        return False


def main():
    a, b, c, d, lim_sugar, lim = map(int, input().split())
    water_list = []
    for i in range(lim // (100 * a) + 1):
        for j in range(lim // (100 * b) + 1):
            if i == 0 and j == 0: continue
            w = 100 * i * a + 100 * j * b
            if w > lim: continue
            water_list.append(w)
    water_list = sorted(list(set(water_list)))

    sugar_list = []
    for i in range(lim // c + 1):
        for j in range(lim // d + 1):
            s = i * c + j * d
            if s > lim: continue
            sugar_list.append(s)
    sugar_list = sorted(list(set(sugar_list)))

    c = 0
    ans = (100 * a, 0)
    for w in water_list:
        for s in sugar_list:
            if total_check(s, w, lim) and concentration(s, w, lim_sugar):
                if c < s * 100 / (s + w):
                    c = s * 100 / (s + w)
                    ans = (s + w, s)
    print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
from math import pi, ceil, floor
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
from bisect import bisect_left, bisect_right, insort_left, insort_right
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def total_check(sugar, water, lim):
    if sugar + water <= lim:
        return True
    else:
        return False


def concentration(sugar, water, lim_sugar):
    if sugar / (sugar + water) <= lim_sugar / (lim_sugar + 100):
        return True
    else:
        return False


def main():
    a, b, c, d, lim_sugar, lim = map(int, input().split())
    water_list = []
    for i in range(lim // (100 * a) + 1):
        for j in range(lim // (100 * b) + 1):
            water_list.append(100 * i * a + 100 * j * b)
    water_list = sorted(list(set(water_list)))
    sugar_list = []
    for i in range(lim // c + 1):
        for j in range(lim // d + 1):
            sugar_list.append(i * c + j * d)
    sugar_list = sorted(list(set(sugar_list)))
    c = 0
    ans = (100 * a, 0)
    for w in water_list:
        for s in sugar_list:
            if w == 0 and s == 0: continue
            if total_check(s, w, lim) and concentration(s, w, lim_sugar):
                if c < s * 100 / (s + w):
                    c = s * 100 / (s + w)
                    ans = (s+w, s)
    print(*ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

water_g=[]
for i in range(f//100+1):
  for j in range(f//100+1):
#    print(i,j)
    w=100*a*i + 100*b*j
    if w<=f:
      water_g.append(w)
water_g=sorted(list(set(water_g)),reverse=True)

sugar_g=[]
for i in range(f*e//100):
  for j in range(f*e//100):
    s=c*i + d*j
    if s<=f:
      sugar_g.append(s)
sugar_g=sorted(list(set(sugar_g)),reverse=True)

#print(water_g, sugar_g)

ans_water=100*a
ans_sugar=0
for water in water_g:
  if water==0:
    break
  for sugar in sugar_g:
    if water+sugar<=f and sugar/water<=e/100:
      if sugar/(sugar+water)>ans_sugar/(ans_sugar+ans_water):
        ans_water=water
        ans_sugar=sugar
print(ans_water+ans_sugar,ans_sugar)

Submission status: Accepted

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

ans = [0, 0, -1]
for a in range(1+F//A):
    for b in range(1+F//B):
        w = 100*A*a + 100*B*b
        if 0 < w < F:
            for c in range(1+(F-w)//C):
                for d in range(1+(F-w)//D):
                    s = C*c + D*d
                    if 0 < w + s <= F and s/w <= E/100:
                        if ans[2] < s/(w+s):
                            ans = [w+s,s,s/(w+s)]
print(*ans[:2])

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
X = []
Y = []
res = 0
for i in range(f+1):
    for j in range(f+1):
        x = 100*a*i+100*b*j
        y = c*i+d*j
        if x > f and y > f:break
        X.append(x)
        Y.append(y)
def ok(x,y):
    return (x//100)*e >= y and x+y <=f
cnt = 0
X.sort()
Y.sort()
ansx = 0
ansy = 0
for x in X:
    for y in Y:
        if x+y > f:break
        
        if ok(x,y):
          
            if x+y == 0:continue
            if res <= 100*y/(x+y):
                res = 100*y/(x+y)
                ansx = x
                ansy = y
        cnt +=1
print(ansx+ansy,ansy)

Submission status: Accepted

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

can = []
for i in range(0, F + 1, 100 * A):
    for j in range(0, F - i + 1, 100 * B):
        water = i + j

        for k in range(0, F - water + 1, C):
            for l in range(0, F - water - k + 1, D):
                salt = k + l
                
                can.append((water, salt))

# (water, salt)
ans = (100 * A, 0)
noudo = 0
for water, salt in can:
    if water == salt == 0: continue

    if (water / 100) * E >= salt:
        tmp = 100 * salt / (water + salt)
        if noudo < tmp:
            ans = (water, salt)
            noudo = tmp

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
A, B, C, D, E, F = map(int, input().split())
s = set()
for i in range(31):
  for j in range(31):
    if (i * A + j * B) * 100 <= F:
      s.add((i * A + j * B) * 100)
    else: break
s.discard(0)
#print(s)
ss = set()
for i in range(3001):
  for j in range(3001):
    if i * C + (j * D) <= F:
      ss.add(i * C + j * D)
    else: break
resw = 100 * A
ress = 0
for water in s:
  for suger in ss:
    if water // 100 * E >= suger and (water + suger <= F):
      if suger * (resw + ress) > (ress * (water + suger)):
        resw = water
        ress = suger
print(resw + ress, ress)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans=[]
for aa in range(31):
  for bb in range(31):
    w=100*(aa*a+bb*b)
    if w>f:break
    n=min(f-w,e*(aa*a+bb*b))
    for cc in range(3001):
      s=cc*c
      if s>n:break
      nn=n-s
      ss=d*(nn//d)
      su=s+ss
      wa=w
      if wa+su==0:continue
      ans.append([100*su/(wa+su),wa,su])
ans.sort(reverse=1)
_,w,s=ans[0]
print(w+s,s)

Submission status: Accepted

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

ab_list = []
for a in range(F//100+1):
    for b in range(F//100+1):
        x = A*a + B*b
        if (0 < 100*x <= F) and (x not in ab_list):
            ab_list.append(x)

cd_list = []
for c in range(F+1):
    for d in range(F+1):
        y = C*c + D*d
        if (y <= F) and (y not in cd_list):
            cd_list.append(y)

max_conc = 0
result = [0, 0]
for i in ab_list:
    for j in cd_list:
        if (100*i + j <= F) and (j <= E*i):
            conc = (100*j) / (100*i + j)
            if conc >= max_conc:
                max_conc = conc
                result = [100*i + j, j]

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

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    wa, wb, sa, sb, sol, lim = list(map(int, readline().split()))
    wa *= 100
    wb *= 100

    water = []
    sugar = []

    for wac in range(lim // wa + 1):
        cw = wa * wac
        for wbc in range(30):
            wadd = cw + wb * wbc
            if wadd <= lim:
                water.append(wadd)
            else:
                break

    for sac in range(3001):
        cs = sa * sac
        if cs > lim:
            break
        for sbc in range(3001):
            sadd = cs + sb * sbc
            if sadd <= lim:
                sugar.append(sadd)
            else:
                break

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

    import bisect

    maxconc = 0
    ans = [0] * 2

    for ww in water[1:]:
        res = min(sol * ww // 100, lim - ww)
        if res < 0:
            continue

        idx = bisect.bisect_right(sugar, res) - 1

        if idx >= 0:
            sw = sugar[idx]

        conc = (100 * sw) / ww

        if conc >= maxconc:
            maxconc = conc
            ans[0] = (ww + sw)
            ans[1] = sw

    print(*ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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)

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

d_max = -1
ans = None
for w in W:
  for s in S:
    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())
sug, dif2 = 0, 100
s = {}
wat1, wat2 = 100*a, 100*b
cap1, cap2 = a*e, b*e
for i in range(1,f//wat1+1):
    for j in range(f//wat2+1):
        if (wat1+cap1)*i+(wat2+cap2)*j<=f:
            s[cap1*i+cap2*j] = wat1*i+wat2*j
if s == {}:
    dif1 = f-wat1
    for i in range(10):
        for j in range(10):
            if 0<=(f-wat1)-(c*i+d*j)<dif1:
                dif1 = (f-wat1)-(c*i+d*j)
                sug3 = c*i+d*j
    print(wat1+sug3, sug3)
    exit(0)
for i in s.keys():
    for j in range(i//c+1):
        for k in range(i//d+1):
            if 0<=i-(c*j+d*k)<dif2:
                dif2 = i-(c*j+d*k)
                wat,sug1,sug2 = s[i],j,k
print(c*sug1+d*sug2+wat, c*sug1+d*sug2)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict(list)
#import bisect
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    a,b,c,d,e,f = readInts()
    water = set()
    sugar = set()
    # water
    # A,B の制約が 1 <= A,B <= 30 だから、ループは31まで回せば位
    for i in range(31):
        for j in range(31):
            w = 100 * a * i + 100 * b * j
            if w <= f: # 水の合計が F より大きくなってはいけない (砂糖0gの時もあるが、)
            # -1g とかはないので
                water.add(w)
    # sugar
    # C,D の制約が、 1 <= C,D <= 3000 であるから、 3001 までまわせばい
    for i in range(3001):
        for j in range(3001):
            s = c * i  + d * j
            if s <= f: # 砂糖の合計が F より大きくなってはいけない
            # 水 0 g はあっても、-1gとかはないから
                sugar.add(s)
    # 濃度の限界値を決める
    nl = e/(100 + e) # *100 すれば、限界の濃度のパーセント
    noudo = -1
    ans1 = 0
    ans2 = 0
    for s in sugar:
        for w in water:
            # 砂糖水をつくる
            sum = s + w
            if sum == 0:# 和が0はだめー てか1 <= だから 1からループ回せばええやんけ
                continue
            x = s/sum # suger / 砂糖水 * 100 すれば%やで
            if sum <= f and x <= nl and x > noudo:
                # 砂糖水は fg以下 , 砂糖水の濃度は限界以下 , 濃度が最大になるまで回せ
                noudo = x
                ans1 = sum
                ans2 = s
    print(ans1,ans2)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

water = set()
sugar = set()

s = 0
a = 0
b = 0

for i in range(30):
    for j in range(30-i):
        if 100*A*i+100*B*j <= F:
            water.add(100*A*i+100*B*j)

water.remove(0)

for i in range(3000):
    for j in range(3000-i):
        if C*i+D*j <= F:
            sugar.add(C*i+D*j)

sugar.remove(0)

WATER = list(water)
SUGAR = list(sugar)

for i in WATER:
    for j in SUGAR:
        if (j <= i*E/100) and (i+j <= F):
            if s == 0:
                s = 100*j /(i + j)
                a = i
                b = j
            else:
                if s < 100*j /(i + j):
                    s = 100*j /(i + j)
                    a = i
                    b = j

if a == 0 and b == 0:
    print(100*A,0)
else:
    print(a+b,b)

Submission status: Accepted

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

Submission status: Accepted

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

# 作れるか判定
def check(goal,ac,bd):
    flag = 0
    for x in range(goal//ac+1):
            if (goal-ac*x)%bd == 0 : flag = 1 ; break
    return flag

# 水W、砂糖Sをまわす
anss = []
for w in range(100,f+1,100):
    for s in range(1,f-w+1):
        if check(w,100*a,100*b) and check(s,c,d) and s<=((w*e)/100):
            conc = 100*s/(w+s) # concentration
            anss.append([conc,w,s])

# 出力
anss.sort(reverse=1)
(w,s) = (anss[0][1],anss[0][2]) if anss else (100*a,0)
print(w+s,s)

Submission status: Accepted

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

# 作れるか判定
def check(goal,ac,bd):
    flag = 0
    for x in range(int(goal//ac)+1):
            if (goal-ac*x)%bd == 0 : flag = 1 ; break
    return flag

# 水W、砂糖Sをまわす
anss = []
for w in range(100,f+1,100):
    for s in range(1,f-w+1):
        if check(w,100*a,100*b) and check(s,c,d) and s<=((w*e)/100):
            conc = 100*s/(w+s) # concentration
            anss.append([conc,w,s])

anss.sort(reverse=1)
(w,s) = (anss[0][1],anss[0][2]) if anss else (100*a,0)
print(w+s,s)

Submission status: Accepted

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

# 作れるか判定
def check(goal,ac,bd):
    flag = 0
    for x in range(int(goal//ac)+1):
            if (goal-ac*x)%bd == 0 : flag = 1 ; break
    return flag

# 水W、砂糖Sをまわす
anss = []
for w in range(100,f+1,100):
    for s in range(1,f-w+1):
        if check(w,100*a,100*b) and check(s,c,d) and s<=((w*e)/100):
            conc = 100*s/(w+s) # concentration
            anss.append([conc,w,s])

anss.sort(reverse=1)
if anss: w,s = anss[0][1],anss[0][2]
else: w,s = 100*a,0
print(w+s,s)

Submission status: Accepted

Solution code:
from fractions import gcd

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

sugar=[]
g=gcd(C,D)
for i in range(0,3000):
    if i>=C*D and i%g==0:
        sugar.append(i)

for i in range(0,D):
    for j in range(0,C):
        if C*D>i*C+j*D:
            sugar.append(i*C+j*D)

sugar.sort()

ans=(-1,1)
for i in range(F//(100*A)+1):
    for j in range(F//(100*B)+1):
        if F>100*A*i+100*B*j:
            x=F-(100*A*i+100*B*j)
            y=(A*i+B*j)*E
            sugarupper=min(x,y)

            start=0
            end=len(sugar)
            while end-start>1:
                test=(end+start)//2
                if sugarupper>=sugar[test]:
                    start=test
                else:
                    end=test

            if sugarupper>=sugar[end]:
                s=sugar[end]
            else:
                s=sugar[start]

            m,n=ans
            if n*s>m*(100*A*i+100*B*j+s):
                ans=(s,100*A*i+100*B*j+s)

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

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int, input().split())
water, suger = 0,0
dense = 0
waters = set()
sugers = set()
for i in range(0,31,a):
  for j in range(i,31,b):
    waters.add(j*100)
for i in range(0,f//2+1,c):
  for j in range(i,f//2+1,d):
    sugers.add(j)
waters = sorted(list(waters))
sugers = sorted(list(sugers))
for w in waters:
  for s in sugers:
    sw = w+s
    if sw > f or s > (w//100)*e or sw == 0:
      continue
    if s / (s+w) >= dense:
      water,suger = sw,s
      dense = s / (s+w)
print(water,suger)