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())
water = set()
for i in range(0,F+1,100*A):
    for j in range(0,F+1,100*B):
        if i + j <= F:
            water.add(i + j)
water = list(water)
water.sort()
sugar = set()
for i in range(0,F+1,C):
    for j in range(0,F+1,D):
        if i + j <= F:
            sugar.add(i + j)
sugar = list(sugar)
sugar.sort()
#print(water)
#print(sugar)
ans = [[0,100*A,0]]
for i in water:
    for j in sugar:
        if i == 0 or j == 0:
            continue
        if i + j <= F and (i//100)*E >= j:
            #print(i,j)
            ans.append([(100*j)/(i+j),i+j,j])
ans.sort()
#print(ans)
print(ans[-1][1],ans[-1][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()
sugar = [0]*(F+1)

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

f = F//2
for c in range(f//C+1):
	for d in range((f-c*C)//D+1):
		sugar[c*C+d*D] = 1

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)

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int,input().split())
mx =- 1
S = set()
W = set()

for a in range(0,F+1,100*A):
  for b in range(0,F+1-a,100*B):
    W.add(a+b)

for c in range(0,F+1,C):
  for d in range(0,F+1-c,D):
    S.add(c+d)

for w in W:
  for s in S:
    if 0<w+s<=F and s<=w*E//100:
      if mx<s/(w+s):
        ans=w+s,s
        mx=s/(w+s)

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

Submission status: Accepted

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

for i in range(31):
    for j in range(31):
        v = 100*A*i+100*B*j
        if v < F:
            a.append(v)
        else:
            break

for i in range(3000//C+2):
    for j in range(3000//D+2):
        v = C*i+D*j
        if v < F:
            b.append(v)
        else:
            break

a.sort()
b.sort()

c = -1
ans = [0, 0]
for ai in a:
    for bi in b:
        t = ai+bi
        if t > 0 and t <= F and (E*ai//100) >= bi:
            tc = 100*bi/(ai+bi)
            if c < tc:
                c = tc
                ans = [t, bi]

print(*ans)

Submission status: Accepted

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

for i in range(3001):
    for j in range(3001):
        v = 100*A*i+100*B*j
        if v <= F:
            a.append(v)
        else:
            break

for i in range(3001):
    for j in range(3001):
        v = C*i+D*j
        if v <= F:
            b.append(v)
        else:
            break

a.sort()
b.sort()

c = -1
ans = [0, 0]
for ai in a:
    for bi in b:
        t = ai+bi
        if t > 0 and t <= F and (E*ai//100) >= bi:
            tc = 100*bi/(ai+bi)
            if c < tc:
                c = tc
                ans = [t, bi]

print(*ans)

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

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

density = 0
ans = (100*A,0)
for i in range(30):  # 操作1の行う回数
    for j in range(30):  # 操作2の行う回数
        if i == 0 and j == 0:
            continue
        elif 100*(A*i+B*j) >= F:
            continue
        else:
            r = min(F-100*(A*i+B*j),E*(A*i+B*j))  # 溶かせる砂糖の上限
            a = r
            for k in range(C):
                s = r-D*k
                if s < 0:
                    break
                else:
                    a = min(a,s % C)
            if density < (r-a)/((r-a)+100*(A*i+B*j)):
                density = (r-a)/((r-a)+100*(A*i+B*j))
                ans = ((r-a)+100*(A*i+B*j),(r-a))

print(*ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100

    # 濃度0%のケース
    if e == 0 or min(a, b) == f:
        print(a, 0)
        sys.exit()

    water = [0] * 6001
    water[0] = True
    for i1 in range(3001):
        if water[i1]:
            water[i1 + a] = True
            water[i1 + b] = True
    sugar = [0] * 6001
    sugar[0] = True
    for i1 in range(3001):
        if sugar[i1]:
            sugar[i1 + c] = True
            sugar[i1 + d] = True

    noudo = 0
    r1 = 0
    r2 = 0
    for i1 in range(1, f + 1):
        if water[i1]:
            for i2 in range(f + 1):
                if i1 + i2 > f:
                    break
                if sugar[i2]:
                    if i1 * e >= i2 * 100:
                        if noudo < i2 / (i1 + i2):
                            noudo = i2 / (i1 + i2)
                            r1 = int(i1 + i2)
                            r2 = int(i2)
                    else:
                        break
    if noudo == 0:
        print(a, 0)
    else:
        print(r1, r2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split(' '))
water = set()
for a in range(0,F,100*A):
  for b in range(0,F,100*B):
    if a+b <= F:
      water.add(a+b)
    else:
      break
sugars = set()
for c in range(0,F,C):
  for d in range(0,F,D):
    if c+d <= F:
      sugars.add(c+d)
    else:
      break
density = 0
sugar = 0
content = 100*A
for x in water:
  for y in sugars:
    if x+y != 0 and x+y <= F and E*x >= 100*y and density < y/(x+y):
      density = y/(x+y)
      sugar = y
      content = x+y
print(content,sugar)

Submission status: Accepted

Solution code:

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    A, B, C, D, E, F = read_values()
    W = set()
    
    for a in range(F // (A * 100) + 1):
        for b in range(F // (B * 100) + 1):
            w = a * 100 * A + b * 100 * B
            if 0 < w <= F:
                W.add(w)

    S = set()
    for c in range(F // C + 1):
        for d in range(F // D + 1):
            s = c * C + d * D
            if 0 <= s <= F:
                S.add(s)
    S = sorted(list(S))
    
    s, t = 0, 100 * A
    for w in W:
        p = min(F - w, math.ceil(E * w / 100))
        f = S[bisect.bisect_right(S, p) - 1]
        if f * 100 > E * w:
            continue

        if s * (w + f) < t * f:
            s, t = f, w + f
    print(t, s)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

x = set()

for i in range(F):
  for j in range(F):
    water = 100 * A * i + 100 * B * j
    if F >=  water:
      x.add(water)
    else:
      break

sugar = water / 100 * E

y = set()

for i in range(F):
  for j in range(F):
    sugar = C * i + D * j
    if F >= sugar:
      y.add(sugar)
    else:
      break

x = list(x) # water
y = list(y) # sugar
percentage = 0
sugarWater = 0
ansSugar = 0

for i in range(len(x)):
  for j in range(len(y)):
    if x[i] + y[j] == 0:
      pass
    elif F >= x[i] + y[j]:
      if y[j] <= E * x[i] / 100:
        p = 100 * y[j] / ( x[i] + y[j] )
        if p >= percentage:
          percentage = p
          sugarWater = x[i] + y[j]
          ansSugar = y[j]

print(str(sugarWater) + " " + str(ansSugar))

Submission status: Accepted

Solution code:
import sys
import bisect
from fractions import Fraction

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

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

    water = set()
    for i in range(31):
        for j in range(31):
            t = i * A * 100 + j * B * 100
            if t <= F:
                water.add(t)
            else:
                break
    water = list(sorted(water))

    sugar = set()
    for i in range(3001):
        for j in range(3001):
            t = i * C + j * D
            if t <= F:
                sugar.add(t)
            else:
                break
    sugar = list(sorted(sugar))

    max_f = 0
    ans = (100 * A, 0)
    for w in water:
        for s in sugar:
            if w + s <= F and s <= (w // 100) * E and w + s != 0:
                if max_f < Fraction(s, w + s):
                    max_f = Fraction(s, w + s)
                    ans = (s + w, s)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
Con = 0
a, b = 0, 0
for i in range(F//100 + 1):
    for j in range(F//100 + 1):
        Water = 100 * A * i + 100 * B * j
        if Water > F:
            break
        for x in range(E * Water // 100 + 1):
            for y in range(E * Water // 100 + 1):
                Sugar = C * x + D * y
                if Water + Sugar > F:
                    break
                if Water * E < Sugar * 100:
                    break
                if Sugar + Water == 0:
                    break
                c = (100 * Sugar) / (Sugar + Water)
                if Con <= c:
                    Con = c
                    a = Water
                    b = Sugar
print(a + b, b)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
inf=float("inf")
a*=100
b*=100
lst=[[inf,0] for _ in range(f//100)]
for i in range(f//b+1):
    for j in range(f//a+1):
        if i==0 and j==0:
            continue
        if (i*b+j*a)<=f:
            lst[(i*b+j*a)//100-1][0]=(i*b+j*a)
sugarlst=[]
C=max(c,d)
D=min(c,d)

for i in range(1500//C+1):
    for j in range((1500-i*C)//D+1):
        sugarlst.append(C*i+D*j)
sugarlst=set(sugarlst)
sugarlst=sorted(sugarlst)

for i in range(f//100):
    if lst[i][0]==inf:
        continue
    for j in sugarlst:
        weight=lst[i][0]+j
        if weight>f or (lst[i][0]//100)*e<j :
            break
        lst[i][1]=j

noudomax=0
for i in lst:
    noudo=i[1]/(i[0]+i[1])
    if noudo>=noudomax:
        ans=i
        noudomax=noudo
if noudomax==0:
    print(a,0)
else:
    print(ans[0]+ans[1],ans[1])

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
W = set(); S = set()
sa = 0; wsa = a * 100

for i in range(0, f + a * 100, a * 100):
    for j in range(0, f + b * 100, b * 100):
        w = i + j
        if w <= f:
            W.add(w)
        else:
            break
for i in range(0, f // 2 + c, c):
    for j in range(0, f // 2 + d, d):
        s = i + j
        if s <= f // 2:
            S.add(s)
        else:
            break
S.remove(0)
for i in W:
    for j in S:
        if e / (100 + e) >= j / (i + j) > sa / wsa and i + j <= f:
            sa, wsa = j, i + j
print(wsa, sa)

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  A,B,C,D,E,F=LI()
  ans_pair=[0,0]
  ans_noudo=0
  for a in range(31):
    for b in range(31):
      for c in range(3001):
        for d in range(3001):

          sato=c*C+d*D
          mizu=100*A*a+100*B*b
          satomizu=sato+mizu
          # if satomizu==2634 and sato==934:
          #   print(satomizu,sato)

          if satomizu==0:
            continue

          if F<satomizu:
            break

          noudo=(100*sato)/(satomizu)
          E_noudo=(100*E)/(100+E)
          if E_noudo<noudo:
            break

          if ans_noudo<=noudo:
            ans_noudo=noudo
            ans_pair=[satomizu,sato]
            # print(noudo,satomizu,sato,mizu,a,b,c,d)

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

# main()
print(main())

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
a, b, c, d, e, f = map(int, input().split())

lim = (f // c) + 1
ans_n = 0
ans_total = 0
ans_su = 0

for ac in range(31):
    for bc in range(31):

        wt = a * ac * 100 + b * bc * 100
        if wt == 0:
            break

        max_su = wt / 100 * e

        for cc in range(lim):
            for dc in range(lim):

                su = c * cc + d * dc

                if (su > max_su) or (wt + su > f):
                    break

                n = (100 * su) / (wt + su)
                if n >= ans_n:
                    ans_n = n
                    ans_total = wt+su
                    ans_su = su

print(ans_total, ans_su)

Submission status: Accepted

Solution code:
from itertools import product

A,B,C,D,E,F = map(int, input().split())
num_a = F // (100 * A)
num_b = F // (100 * B) 
num_c = int((F * E / (E + 100)) // C)
num_d = int((F * E / (E + 100)) // D)

def check_w(w_mizu, w_sato, F):
  return w_mizu + w_sato <= F

def check_tokeru(w_mizu, w_sato, E):
  return 100 * w_sato / (w_mizu + w_sato) <= 100 * E / (100 + E)

def culc_density(w_mizu, w_sato):
  return 100 * w_sato / (w_mizu + w_sato)

max = [100 * A, 0, 0]  # total, sato, density
for _a, _b,  in product(range(num_a + 1), range(num_b + 1)): 
  w_mizu = (A * _a + B * _b) * 100
  if w_mizu == 0 or w_mizu >= F:
    continue
    
  for _c, _d in product(range(num_c + 1), range(num_d + 1)):
    w_sato = (C * _c + D * _d)
    if w_sato == 0 or w_sato >= F or (w_mizu + w_sato) > F:
      continue
    
    density = culc_density(w_mizu, w_sato)
  
    if check_w(w_mizu, w_sato, F) and check_tokeru(w_mizu, w_sato, E):
      if max[2] < density:
        max[0] = w_mizu + w_sato
        max[1] = w_sato
        max[2] = density

if max[0]:
  print(max[0], max[1])

Submission status: Accepted

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

density = -1
s_water = -1
sugar = -1
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:
                    continue
                if w + s > F or w + s < 100*A:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = w + s
                        sugar = s
print(s_water, sugar)

Submission status: Accepted

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

ans = -1
ans_water = -1
ans_sugar = -1
for ia in range(f//(a*100)+2):
    water = 100*a*ia
    if water > f or water == 0: continue
    for ib in range(f//(b*100)+2):
        if ib != 0: water += 100*b
        if water > f or water == 0: continue
        for ic in range(f//c+1):
            sugar = c*ic
            if sugar/(water//100) > e: continue
            for id in range(f//d+1):
                if id != 0: sugar+=d
                if sugar/(water//100) > e: continue
                if sugar + water > f: continue
                if (100*sugar)/(sugar+water) > ans:
                    ans = (100*sugar)/(sugar+water)
                    ans_water = water
                    ans_sugar = sugar
print(ans_sugar+ans_water, ans_sugar)

Submission status: Accepted

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

water_masses = set()
for i in range(31):
    for j in range(31):
        mass = 100 * A * i + 100 * B * j
        if 0 < mass and mass <= F:
            water_masses.add(mass)

sugar_masses = set()
for i in range(3000 // C + C):
    for j in range(3000 // D + D):
        mass = C * i + D * j
        if mass <= F:
            sugar_masses.add(mass)

res_water = 100 * A
res_sugar = 0
for m_water in water_masses:
    for m_sugar in sugar_masses:
        if m_water + m_sugar > F:
            continue

        con = m_sugar / (m_water + m_sugar)
        if con <= (E / (100 + E)) and con > (res_sugar / (res_water + res_sugar)):
            res_water = m_water
            res_sugar = m_sugar


print(res_water + res_sugar, res_sugar)

Submission status: Accepted

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

ans = []
memo = []
for a in range(31):
    for b in range(31):
        for c in range(100):
            for d in range(100):
                w = 100 * A * a + 100 * B * b
                s = C * c + D * d
                if  w + s > F: continue
                if E * w / 100 >= s and w + s != 0:
                    ans.append(100 * s / (w + s))
                    memo.append([w + s, s])

print(*memo[ans.index(max(ans))])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
g=[-1]*9999
g[a*100]=0
g[b*100]=0
h=[a*100,0]
p=0
for i in range(1,f+1):
    if g[i]==-1:
        continue
    if (g[i]+c)/(i-g[i])<=e*0.01:
        g[i+c]=max(g[i]+c,g[i+c])
    if (g[i]+d)/(i-g[i])<=e*0.01:
        g[i+d]=max(g[i]+d,g[i+d])
    g[i+a*100]=max(g[i+a*100],g[i])
    g[i+b*100]=max(g[i+b*100],g[i])
    if g[i]/i>p:
        p=g[i]/i
        h=[i,g[i]]
print(*h)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
ans=[-1]*9999
ans[a*100]=0
ans[b*100]=0
fin=[a*100,0]
p=0
for i in range(1,f+1):
    if ans[i]==-1:
        continue
    if (ans[i]+c)/(i-ans[i])<=e*0.01:
        ans[i+c]=max(ans[i]+c,ans[i+c])
    if (ans[i]+d)/(i-ans[i])<=e*0.01:
        ans[i+d]=max(ans[i]+d,ans[i+d])
    ans[i+a*100]=max(ans[i+a*100],ans[i])
    ans[i+b*100]=max(ans[i+b*100],ans[i])
    if ans[i]/i>p:
        p=ans[i]/i
        fin=[i,ans[i]]
print(*fin)

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
ans = [-1]*10000
# ans[0] = 0
ans[a*100] = 0
ans[b*100] = 0
q1 = a*100
q2 = b*100
p = 0
fin = [a*100,0]
for i in range(1,f+1):
    if ans[i] == -1:
        continue
    if (ans[i]+c)/(i-ans[i]) <= e*0.01:
        ans[i+c] = max(ans[i]+c,ans[i+c])
    if (ans[i]+d)/(i-ans[i]) <= e*0.01:
        ans[i+d] = max(ans[i]+d,ans[i+d])
    ans[i+a*100] = max(ans[i+a*100],ans[i])
    ans[i+b*100] = max(ans[i+b*100],ans[i])
    if i != 0:
        if ans[i]/i > p:
            # print(p,i)
            p = ans[i]/i
            fin = [i,ans[i]]
# print(ans[190:210])
print(*fin)

Submission status: Accepted

Solution code:
from fractions import Fraction
from itertools import product

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

a_max = F // (A * 100)
b_max = F // (B * 100)

waters = set()

for a, b in product(range(0, a_max + 1), range(0, b_max + 1)):
    w = (a * A + b * B) * 100
    if w > F:
        continue

    waters.add(w)

waters = sorted(waters)[1:]
sugars = []

for w in sorted(waters):
    f1 = F - w
    f2 = w // 100 * E
    c_max = min(f1 // C, f2 // C)
    d_max = min(f1 // D, f2 // D)

    max_sugar = 0

    for c, d in product(range(0, c_max + 1), range(0, d_max + 1)):
        s = C * c + D * d
        if s > f1 or s > f2:
            continue
        max_sugar = max(max_sugar, s)

    sugars.append(max_sugar)

dense = [Fraction(s, s + w) for w, s in zip(waters, sugars)]

max_dense = 0
index = -1
for i, d in enumerate(dense):
    if d > max_dense:
        max_dense = d
        index = i

if index == -1:
    print(A * 100, 0)
else:
    print(waters[index] + sugars[index], sugars[index])

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

A,B,C,D,E,F = I()
lim1 = F//(100*A)
lim2 = F//(100*B)
ans = 0
ansnum = 0
for i in range(lim1+1):
    for j in range(lim2+1):
        w = 100*i*A+100*j*B
        if i == j == 0:
            continue
        if w > F:
            continue
        r = F-w
        num = 0
        lim3 = min(r,(i*A+j*B)*E)//C
        for k in range(lim3+1):
            num = max(num,k*C+((min(r,(i*A+j*B)*E)-k*C)//D)*D)
        if 100*num/(w+num) > ansnum:
            ans = [w+num,num]
            ansnum = 100*num/(w+num)
if ans == 0:
    print(A*100,0)
else:
    print(*ans)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
W = set(); S = set()
sa = 0; wsa = a * 100
for i in range(0, f + a * 100, a * 100):
    for j in range(0, f + b * 100, b * 100):
        w = i + j
        if w <= f:
            W.add(w)
        else:
            break
for i in range(0, f // 2 + c, c):
    for j in range(0, f // 2 + d, d):
        s = i + j
        if s <= f // 2:
            S.add(s)
        else:
            break
S.remove(0)
for i in W:
    for j in S:
        if e / (100 + e) >= j / (i + j) > sa / wsa and i + j <= f:
            sa, wsa = j, i + j
print(wsa, sa)

Submission status: Accepted

Solution code:
# Atcoder Review Problems
# sugar Water
A, B, C, D, E, F = map(int, input().split())
# 別々に構成してもいい
dp_sugar = [0 for i in range(3001)]
dp_sugar[0] = True
for i in range(1, 3001):
    if i >= C:
        dp_sugar[i] |= dp_sugar[i-C]
    if i >= D:
        dp_sugar[i] |= dp_sugar[i-D]

dp_water = [0 for i in range(3001)]
dp_water[0] = 1
for i in range(1, 3001):
    if i >= 100*A:
        dp_water[i] |= dp_water[i-100*A]
    if i >= 100*B:
        dp_water[i] |= dp_water[i-100*B]

data = []
for i in range(1, F+1):
    # 水の量をiで固定
    if dp_water[i]:
        submax = 0
        for j in range(F+1-i):
            # 砂糖の量j
            if dp_sugar[j] and 100*j <= E*i:
                submax = j
        data.append((i+submax, submax, 100*submax/(i+submax)))
data.sort(key=lambda x: x[-1])
x,y,z=data[-1]
print(x,y)

Submission status: Accepted

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

density = -1
s_water = -1
sugar = -1
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:
                    continue
                if w + s > F or w + s < 100*A:
                    continue
                if w/100 * E >= s:
                    tmp = 100*s / (w + s)
                    if tmp > density:
                        density = tmp
                        s_water = w + s
                        sugar = s
print(s_water, sugar)

Submission status: Accepted

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

DP=[-1 for _ in range(f+1)]
DP[a]=0
if b<=f:DP[b]=0
for i in range(f+1):
    if DP[i]==-1:continue
    for j in a,b:
        if i+j<=f:DP[i+j]=DP[i]
    for j in c,d:
        if i+j<=f and 100*(DP[i]+j)/(i+j)<=100*e/(100+e):
            DP[i+j]=DP[i]+j

ans,water=0,[a,0]
for i,j in enumerate(DP):
    if i==0 or j==-1:continue
    if ans<100*j/i:
        ans=100*j/i
        water=[i,j]
print(*water)

Submission status: Accepted

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

DP=[-1 for _ in range(f+3000)]
DP[a],DP[b]=0,0
for i in range(f+1):
    if DP[i]==-1:continue
    for j in a,b:
        if i+j<=f:DP[i+j]=DP[i]
    for j in c,d:
        if i+j<=f and 100*(DP[i]+j)/(i+j)<=100*e/(100+e):
            DP[i+j]=DP[i]+j

ans,water=0,[a,0]
for i,j in enumerate(DP):
    if i==0:continue
    if ans<100*j/i:
        ans=100*j/i
        water=[i,j]
print(*water)

Submission status: Accepted

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

a *=100
b *=100
DP=[[0,0] for _ in range(f+3000)]
DP[a][0]=a
DP[b][0]=b

for i in range(f+1):
    if DP[i][0]==0:continue
    for j in a,b:
        if i+j<=f:
            if DP[i][1]*100/(i+j)>=DP[i+j][1]*100/(i+j):
                DP[i+j]=[i+j,DP[i][1]]
    for j in c,d:
        if i+j<=f:
            if 100*(DP[i][1]+j)/(i+j)<=100*e/(100+e):
                if 100*(DP[i][1]+j)/(i+j)>=100*(DP[i+j][1])/(i+j):
                    DP[i+j]=[i+j,DP[i][1]+j]

ans,water=0,[a,0]
for x,y in DP:
    if x==0:continue
    if 100*y/x>ans:
        ans=100*y/x
        water=[x,y]
print(*water)

Submission status: Accepted

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

DP=[[0,0] for _ in range(f+3000)]
DP[a*100][0]=a*100
DP[b*100][0]=b*100

for i in range(f+1):
    if DP[i][0]==0:continue
    for j in a,b:
        if i+j*100<=f:
            j *=100
            if DP[i][1]*100/(i+j)>=DP[i+j][1]*100/(i+j):
                DP[i+j]=[i+j,DP[i][1]]
    for j in c,d:
        if i+j<=f:
            if 100*(DP[i][1]+j)/(i+j)<=100*e/(100+e):
                if 100*(DP[i][1]+j)/(i+j)>=100*(DP[i+j][1])/(i+j):
                    DP[i+j]=[i+j,DP[i][1]+j]

ans,water=0,[a*100,0]
for x,y in DP:
    if x==0:continue
    if 100*y/x>ans:
        ans=100*y/x
        water=[x,y]
print(*water)

Submission status: Accepted

Solution code:
inf=10**8
a,b,c,d,e,f=map(int,input().split())
a,b=100*a,100*b
DP=[inf]*(f+max(a,b)+1)
DP[a],DP[b]=0,0

for i in range(f+1):
    if DP[i]!=inf:
        DP[i+a]=DP[i]
        DP[i+b]=DP[i]
        for j in c,d:
            if 100*(DP[i]+j)/(i+j)<=100*e/(100+e):
                DP[i+j]=max(DP[i],DP[i]+j)

ans,index=0,[a,0]
for i in range(f+1):
    if DP[i]!=inf:
        if ans<100*DP[i]/i:
            ans=100*DP[i]/i
            index=[i,DP[i]]

print(*index)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=list(map(int,input().split()))
max=0
satou=0
water=0
for i in range(31):
    for j in range(31):
        for k in range(101):
            for l in range(101):
                a=100*A*i+100*B*j
                s=C*k +D*l
                if a==0:break
                if a+s<=F and (a/100)*E>=s :
                    if max<100*s/(a+s):
                        max=100*s/(a+s)
                        water=a+s
                        satou=s
if satou>0:
    print(water,satou)
else:
    print(100*A,0)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
maxsugar=0
maxwater=100*a
for i in range(31):
    for j in range(31):
        for k in range(3001):
            water=100*a*i+100*b*j
            sugar=c*k
            if water+sugar>f:
                continue
            if sugar>(a*i+b*j)*e:
                continue
            sugar+=min((f-(water+sugar))//d*d,((a*i+b*j)*e-c*k)//d*d)
            if 100*maxsugar*(water+sugar)<100*sugar*(maxsugar+maxwater):
                maxsugar=sugar
                maxwater=water
print(maxsugar+maxwater,maxsugar)