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:
import math
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

def AddV2(v,w):
    return [v[0]+w[0],v[1]+w[1]]

dir4 = [[1,0],[0,1],[-1,0],[0,-1]]


def clamp(x,y,z):
    return max(y,min(z,x))

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
#
def Zaatsu(a):
    a.sort()
    now = a[0][0]
    od = 0
    for i in range(n):
        if(now==a[i][0]):
            a[i][0]=od
        else:
            now = a[i][0]
            od+=1
            a[i][0] = od
    
    a.sort(key = lambda x : x[1])
    return a

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

def rl(x):
    return range(len(x))

# a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#21-


a,b,c,d,e,f= list(map(int, input().split()))
ans = [100,-1]
maxim = -0.1

for i in range(30):
    for j in range(30):
        for k in range(1500):
            water = 100*(a*i+b*j)
            if(water==0):
                continue
            sugar = c*k
            maxSugar = min(e*water//100,f-water)
            l = (maxSugar - sugar)//d
            if(l<0):
                continue
            sugar = c*k + d*l
            ratio = [sugar,(sugar+water)]
            #if(i==1 and j==0):print(i,j,k,l)
            if(sugar+water>f):
                continue
            #if(i==1 and j==0): print(i,j,k,l)
            if(ratio[1]*ans[1]<ratio[0]*ans[0] and sugar+water<=f):
                maxim = ratio
                ans = [water+sugar,sugar]
                #print(i,j,k,l)

print(*ans)

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
mizu=[0]*31
mizu[0]=1
satou=[0]*1501
satou[0]=1
noudo=0
for i in range(31):
 if i>=A:
  mizu[i]+=mizu[i-A]
 if i>=B:
  mizu[i]+=mizu[i-B]
for i in range(1501):
 if i>=C:
  satou[i]+=satou[i-C]
 if i>=D:
  satou[i]+=satou[i-D]
for i in range(31):
 for j in range(1501):
  if mizu[i]>0 and satou[j]>0 and (i+j)>0:
   if  j<=E*i and 100*i+j<=F and 100*j/(i+j)>=noudo:
    noudo=100*j/(i+j)
    ans=[100*i+j,j]
print(*ans)

Submission status: Accepted

Solution code:
import heapq

def main():
    A, B, C, D, E, F = map(int, input().split())
    dp = {0: 0}
    mt, ms = 100 * A, 0
    for i in range(1, F + 1):
        s = -1
        if i - 100 * A in dp:
            s = max(s, dp[i - 100 * A])
        if i - 100 * B in dp:
            s = max(s, dp[i - 100 * B])
        if i - C in dp:
            if dp[i - C] + C <= E * (i - C - dp[i - C]) // 100:
                s = max(s, dp[i - C] + C)
        if i - D in dp:
            if dp[i - D] + D <= E * (i - D - dp[i - D]) // 100:
                s = max(s, dp[i - D] + D)
        if s >= 0:
            if 100 * s * mt > 100 * ms * i:
                mt, ms = i, s
            dp[i] = s
    return mt, ms 

print(*main())

Submission status: Accepted

Solution code:
def main():
    A, B, C, D, E, F = list(map(int, input().split()))
    A *= 100
    B *= 100
    dp = [[0] * 3000 for _ in range(3000)]
    dp[0][0] = 1
    m = 0
    mt = (A, 0)
    for i in range(3000):
        for j in range(3000):
            if dp[i][j] == 0:
                continue
            if i + A <= F:
                dp[i+A][j] = 1
            if i + B <= F:
                dp[i+B][j] = 1
            if i + C <= F:
                dp[i+C][j+C] = 1
                if (j+C)/(i+C) > m and (j+C)/(i+C)<= E/(100+E):
                    m = (j+C)/(i+C)
                    mt = ((i+C), (j+C))
            if i + D <= F:
                dp[i+D][j+D] = 1
                if (j+D)/(i+D) > m and (j+D)/(i+D)<= E/(100+E):
                    m = (j+D)/(i+D)
                    mt = ((i+D), (j+D))
    return mt
mt = main()
print(mt[0], mt[1])

Submission status: Accepted

Solution code:
a,b,c,d,e,f = map(int,input().split())
maxm = 100*a
maxs = 0
water = set()
suger = set()
for i in range(31):
    for j in range(31):
        if i*a*100 + j*b*100 <= f and i*a*100 + j*b*100 > 0:
            water.add(i*a*100+j*b*100)
for i in range(f+1):
    for j in range(f+1):
        suger.add(c*i+d*j)
for i in water:
    for j in suger:
        if i*e//100 >= j and i+j <= f:
            tmpm = i + j
            tmps = j
            if tmps*maxm > maxs*tmpm:
                maxm = tmpm
                maxs = tmps
print(maxm,maxs)

Submission status: Accepted

Solution code:
def cal(A,B,C,D,E,F):
    div = [0 for _ in range(4)]
    div[0] = F // (100 * A)
    div[1] = F // (100 * B)
    if B % A == 0:
        div[1] = 0
    div[2] = (F * E) // ((100 + E) * C)
    div[3] = (F * E) // ((100 + E) * D)
    if D % C == 0:
        div[3] = 0

    concent,concent_max = -1.0,[0,0]
    for i2 in range(div[1]+1):
        for i1 in range(div[0]+1):
            for j2 in range(div[3]+1):
                for j1 in range(div[2]+1):
                    if 100 * (A * i1 + B * i2) + (C * j1 + D * j2) <= F \
                    and (C * j1 + D * j2) <= E * (A * i1 + B * i2) \
                    and ((i1 != 0) or (i2 != 0)):
                        if concent < (C * j1 + D * j2) / (A * i1 + B * i2):
                            concent = (C * j1 + D * j2) / (A * i1 + B * i2)
                            concent_max = [C * j1 + D * j2 , (A * i1 + B * i2) * 100]
                    else:
                        break

    return concent_max

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

    concent_max = cal(A,B,C,D,E,F)
    print(concent_max[0] + concent_max[1],concent_max[0])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

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

A = list(range(0,101))
B = list(range(0,101))
ptr = list(itertools.product(A, repeat=2))
ptr2 = list(itertools.product(B, repeat=2))

tmp = 0
ans = [0,0]

for a1,b1 in ptr:
    for c1,d1 in ptr2:
        if (a*a1+b*b1) * e >= c * c1 + d * d1 and (a*a1+b*b1) * 100 + c * c1 + d * d1 <= f:
            if tmp*(a*a1+b*b1) <= (c * c1 + d * d1) and not (a1 == 0 and b1 == 0 and c1 == 0 and d1 == 0):
                tmp = (c * c1 + d * d1)/(a*a1+b*b1)
                ans = [(a*a1+b*b1) * 100 + c * c1 + d * d1, c * c1 + d * d1]

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

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
i=0
answ=0
anss=0
cnt=0
while 100*a*i<=f:
  j=0
  while 100*a*i+100*b*j<=f:
    k=0
    while c*k<=(a*i+b*j)*e:
      l=0
      if (a*i+b*j+c*k+d*l)!=0:
        if cnt<100*(c*k+d*l)/(a*i+b*j+c*k+d*l):
          if (a*i+b*j)*100+c*k+d*l<=f:
            cnt=100*(c*k+d*l)/(a*i+b*j+c*k+d*l)
            answ=(a*i+b*j)*100
            anss=c*k+d*l
      l=((a*i+b*j)*e-c*k)//d
      if l>0:
        if (a*i+b*j+c*k+d*l)!=0:
          if cnt<100*(c*k+d*l)/(a*i+b*j+c*k+d*l):
            if (a*i+b*j)*100+c*k+d*l<=f:
              cnt=100*(c*k+d*l)/(a*i+b*j+c*k+d*l)
              answ=(a*i+b*j)*100
              anss=c*k+d*l
      l=(f-(a*i+b*j)*100-c*k)//d
      if l>0:
        if (a*i+b*j+c*k+d*l)!=0:
          if cnt<100*(c*k+d*l)/(a*i+b*j+c*k+d*l):
            if c*k+d*l<=(a*i+b*j)*e:
              cnt=100*(c*k+d*l)/(a*i+b*j+c*k+d*l)
              answ=(a*i+b*j)*100
              anss=c*k+d*l
      k=k+1
    j=j+1
  i=i+1
temp=0
i=0
while 100*a*i<=f:
  j=0
  while 100*a*i+100*b*j<=f:
    temp=max(temp,100*a*i+100*b*j)
    j=j+1
  i=i+1
if 100*a+c>f:
  print(100*a,0)
elif temp//100*e<c:
  print(temp,0)
else:
  print(answ+anss,anss)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
A,B,C,D,E,F = IL()

W = set()
for i in range(F//(100*A)+1):
  W |= set(100*A*i+100*B*j for j in range((F-(100*A*i))//(100*B)+1))

S = set()
for i in range(F//C+1):
  S |= set(C*i+D*j for j in range((F-(C*i))//D+1))
  
res = [100*A,0]
W = list(W)
S = list(S)
for w in W:
  for s in S:
    if 0 < w+s <= F:
      if res[1]*(w+s) < res[0]*s  and (100+E)*s <= E*(w+s):
        res = [w+s,s]
print(*res)

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
A *= 100
B *= 100
dp = [[False]*(F+1) for i in range(F+1)]
dp[0][0] = True
for f in range(F+1):
  for s in range(F+1):
    if dp[f][s]:
      if f+C<=F and s+C<=F:
        dp[f+C][s+C] = True
      if f+D<=F and s+D<=F:
        dp[f+D][s+D] = True
      if f + A <= F:
        dp[f+A][s] = True
      if f + B <= F:
        dp[f+B][s] = True

ans = (float('inf'), 0)
for f in range(F+1):
  for s in range(F+1):
    if dp[f][s]:
      if s*100 <= E*(f-s):
        if ans[1]*f < ans[0]*s:
          ans = (f, s)

if ans[0] < float('inf'):
  print(*ans)
else:
  print(A, 0)

Submission status: Accepted

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

# A + Bの組み合わせはせいぜい1～30のうち作れる数字のみなので全探索

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

ans = [0,0]
maxrate = 0.0
for a in range(0,F,100 * A):
  for b in range(0,F,100 * B):
    if a == 0 and b == 0:
      continue
    if a + b > F:
      break
    water = a + b
    # waterに対して溶ける最大量は (a + b) * E
    limit = min(((a + b) // 100) * E, F - water)
    maxsugar = 0
    for c in range(0,limit + 1,C):
      for d in range(0,limit + 1,D):
        if c + d > limit:
          break
        if c + d > maxsugar:
          maxsugar = c + d
          rate = maxsugar / (water + maxsugar)
          if rate > maxrate:
            maxrate = rate
            ans = [water + maxsugar, maxsugar]

if maxrate == 0.0:
  print(min(A,B) * 100, 0)
  exit(0)

print(*ans)

Submission status: Accepted

Solution code:
def concentration(water, suger):
  return 100 * suger / (water + suger)

WATER_A, WATER_B, SUGER_C, SUGER_D, MELT_PER_100, LIMIT = map(int, input().split())

WATER_A *= 100
WATER_B *= 100
# 砂糖の溶解率の上限
MELT_PERCENT_LIMIT = concentration(100, MELT_PER_100)

wa = wb = sc = sd = 0

water_set = set()
while wa * WATER_A <= LIMIT:
  while wb * WATER_B <= LIMIT:
    water = wa * WATER_A + wb * WATER_B
    if water <= LIMIT:
      water_set.add(water)
    wb += 1
  wb = 0
  wa += 1

suger_set = set()
while sc * SUGER_C <= LIMIT:
  while sd * SUGER_D <= LIMIT:
    suger = sc * SUGER_C + sd * SUGER_D
    if suger <= LIMIT:
      suger_set.add(suger)
    sd += 1
  sd = 0
  sc += 1

ans_suger_water = 0
ans_suger = 0
# 最大溶解率を保持するための変数
max_concentration = 0

for water in water_set:
  for suger in suger_set:
    # 砂糖水の量が0より大きく制限量以下以外の場合は次のループへ
    if not (0 < water + suger <= LIMIT):
      continue
    # 砂糖濃度計算
    suger_precent = concentration(water, suger)
    # 砂糖濃度が最高を更新かつ限界濃度を超えていなければ答えを更新
    if max_concentration <= suger_precent <= MELT_PERCENT_LIMIT:
      max_concentration = suger_precent
      ans_suger_water = water + suger
      ans_suger = suger

print(ans_suger_water, ans_suger)

Submission status: Accepted

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

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

s2 = set()
for i in range(0, F, C):
    for j in range(0, F, D):
        if i + j <= F:
            s2.add(i + j)

concent = 0
total = 0
sugar = 0
for ab in s1:
    for cd in s2:
        if cd / ab <= E and ab * 100 + cd <= F:
            if concent <= cd / ab:
                concent = cd / ab
                total = ab * 100 + cd
                sugar = cd


print(total, sugar)

Submission status: Accepted

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

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

s2 = set()
for i in range(0, F, C):
    for j in range(0, F, D):
        if i + j <= F:
            s2.add(i + j)

max_concent = 0
total = 0
sugar = 0
for ab in s1:
    for cd in s2:
        if cd <= E * ab and cd <= F - 100 * ab:
            if max_concent <= cd / ab:
                max_concent = cd / ab
                total = 100 * ab + cd
                sugar = cd


print(total, sugar)

Submission status: Accepted

Solution code:
import sys

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

q = [A, B]
water = []
while q:
    num = q.pop()
    if 100 * num <= F:
        water.append(num)
    else:
        continue
    q.append(num + A)
    q.append(num + B)

water = set(water)
w_ans = 0
s_ans = 0
nodo_ans = -1 # 濃度が0のときにも答えの更新が行われるようにする
V = [C, D]

for w in water:
    max_s = min(E * w, F - w * 100) # 溶かせる砂糖の量の最大値
    dp = [[0] * (max_s + 1) for _ in range(3)]
    dp[0][0] = 1
    for i in range(2):
        v = V[i]
        for j in range(max_s + 1):
            if j - v >= 0:
                dp[i + 1][j] = max(dp[i][j], dp[i][j - v], dp[i + 1][j - v])
            else:
                dp[i + 1][j] = dp[i][j]

    for i, d in enumerate(dp[2]):
        if d > 0:
            nodo = i * 100 / (100 * w + i)
            if nodo_ans < nodo:
                s_ans = i
                w_ans = w * 100
                nodo_ans = nodo

print(w_ans + s_ans, s_ans)

Submission status: Accepted

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

answ=1
anss=0

for b in range(F//(100*B)+1):
    for a in range((F-100*B*b)//(100*A)+1):
        w=100*A*a+100*B*b
        if w==0:
            continue
        smax=min(F-w,w*E//100)
        s=0
        for d in range(smax//D+1):
            c=(smax-d*D)//C
            tmps=c*C+d*D

            s=max(s,tmps)

        if anss*(s+w)<=s*(anss+answ):
            answ=w
            anss=s

print('{} {}'.format(answ+anss,anss))

Submission status: Accepted

Solution code:
A, B, C, D, E, F = map(int, input().split())
x_list = []
y_list = []
noudo = []
for i in range(F):
    for j in range(F):
        if C*i + D*j <= F:
            y_list.append(C*i + D*j)

for i in range(F//100):
    for j in range(F//100):
        if A*i + B*j <= F//100:
            x_list.append(100 * (A*i + B*j))
x_list.remove(0)
for x in x_list:
    for y in y_list:
        if x+y <= F and y / (x+y) <= E / (100+E):
            noudo.append([y / (x+y), x+y, y])

ans = max(noudo)
print(ans[1], ans[2])

Submission status: Accepted

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


maxab = f //100
maxcd = f*e //(100+e)

res =[]

for i in range(maxab//a +1):
    for j in range(maxab//b +1):
        wa = a*i + b*j
        if 0 < wa*100 < f:
            for k in range(maxcd//c +1):
                for l in range(maxcd//d +1):
                    su = c*k + d*l
                    if (su <= wa*e) and wa*100+su <= f:
                        g = su/(wa*100+su)
                        res.append([g,wa*100+su,su])
        else:
            pass

resr = sorted(res,key=lambda x: x[0], reverse=True)

print(resr[0][1],resr[0][2])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())


    def calc_possible_gram(x, y, f):
        """f 以下の範囲で x, y を任意回足して作れるグラム数を列挙しソートして返す (0 は除く)"""
        table = [False] * (f + 1)
        table[0] = True
        iteration = f // x
        for _ in range(iteration):
            for i in range(f):
                if table[i]:
                    if i + x <= f:
                        table[i+x] = True
                    if i + y <= f:
                        table[i+y] = True
        return [ind for ind in range(f+1) if table[ind]][1:]

    
    a, b, c, d, e, f = mi()
    water = calc_possible_gram(100*a, 100*b, f)
    sugar = calc_possible_gram(c, d, f)
    # print(water)
    # print(sugar)

    concentration_max = 0
    water_memo = 100*a
    sugar_memo = 0
    for w in water:
        soluble_sugar = min(f - w, (w * e) // 100)
        ind = bisect_right(sugar, soluble_sugar)
        
        s = sugar[ind-1] if ind != 0 else 0
        c = (100*s)/(w+s)
        if concentration_max <= c:
            # print(f"{w} {soluble_sugar} {s} {c}")
            concentration_max = c
            water_memo, sugar_memo = w, s
    
    print("{} {}".format(water_memo+sugar_memo, sugar_memo))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    A, B, C, D, E, F = map(int, input().split())
    ans = [100*A,0]
    # 水の量で全探索する
    N = F // (100*A)
    M = F // (100*B)
    for i in range(N+1):
        for j in range(M+1):
            if i == j == 0:# 水なしはだめ
                continue
            water = 100*A*i + 100*B*j
            if water > F:
                continue
            K = (F - water) // C
            L = (F - water) // D
            for k in range(K+1):
                for l in range(L+1):
                    sugar = C*k + D*l
                    if sugar > (A*i + B*j) * E:# 溶け残りはだめ
                        continue
                    if water + sugar > F:# 溢れたらだめ
                        continue
                    if ans[1] / ans[0] < sugar / (sugar+water):
                        ans = [water+sugar, sugar]
            
    print(*ans)
                    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
def main():
  A, B, C, D, E, F = map(int, input().split())
  water = [100*A*(i)+100*B*(j) for i in range(31) for j in range(31-i)]
  water = set(water)
  sugar_max = int(F*(E/(100+E)))
  sugar = [C*i + D*j for i in range(sugar_max//C+10) for j in range((sugar_max-C*i)//D+10)]
  sugar = set(sugar)
  ans = [0, 0]
  max_den = 0
  for p in itertools.product(water, sugar):
    if p[0] == 0 and p[1] == 0:continue
    if max_den <= p[1]/(p[0]+p[1]) <= E/(100+E) and p[0] + p[1] <= F:
      max_den = p[1]/(p[0]+p[1])
      ans[0] = p[0] + p[1]
      ans[1] = p[1]
  print(*ans)
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    A, B, C, D, E, F = map(int, input().split())
    water = [0]*F**2
    sugar = [0]*F**2

    sugar_idx = 0
    for i in range(F+1):
        for j in range(F+1):
            y = i*C+j*D
            if y <= F:
                sugar[sugar_idx] = y
                sugar_idx += 1

    water_idx = 0
    for i in range(F+1):
        for j in range(F+1):
            x = i*100*A+j*200*D
            if x <= F:
                water[water_idx] = x
                water_idx += 1

    dens = 0
    ans = (0, 0)

    for i in range(water_idx):
        for j in range(sugar_idx):
            w=water[i]
            s=sugar[j]
            if 0 < w+s <= F:
                if s/(w+s) >= dens and s/(w+s) <= E/(100+E):
                    dens = s/(w+s)
                    ans = (w+s, s)
    print(*ans)


resolve()

Submission status: Accepted

Solution code:
def main():
    A, B, C, D, E, F = list(map(int, input().split(' ')))
    ans_total, ans_sugar = 100 * A, 0
    a = 0
    while 100 * A * a <= F:
        b = 0
        while 100 * (A * a + B * b) <= F:
            if a == b == 0:
                b += 1
                continue
            c = 0
            while 100 * (A * a + B * b) + C * c <= F:
                if E * (A * a + B * b) < C * c:
                    break
                d = 0
                while 100 * (A * a + B * b) + C * c + D * d <= F:
                    if E * (A * a + B * b) < C * c + D * d:
                        break
                    sugar, total = C * c + D * d, 100 * (A * a + B * b) + C * c + D * d
                    if sugar * ans_total > ans_sugar * total:
                        ans_sugar = sugar
                        ans_total = total
                    d += 1
                c += 1
            b += 1
        a += 1
    print('{} {}'.format(ans_total, ans_sugar))


if __name__ == '__main__':
    main()