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=[]
for i in range(F//(100*B)+1):
  for j in range((F-100*B*i)//(100*A)+1):
    water.append(100*A*j+100*B*i)
water=sorted(list(set(water)))
suger=[]
for i in range(F//(C)+1):
  for j in range((F-C*i)//D+1):
    suger.append(C*j+D*i)
suger=sorted(list(set(suger)))
Water=0
Suger=0
ans=0
if (A*100+min(C,D)>F):
  print(A*100,0)
else:
  for i in range(len(water)):
    if i==0:
      continue
    for j in range(len(suger)):
      if water[i]+suger[j]>F:
        break
      c=float(suger[j]*100/water[i])
      if c<=E:
        if c>ans:
          ans=c
          Water=water[i]+suger[j]
          Suger=suger[j]
  if Water==0:
    print(A*100,0)
  else:
    print(Water,Suger)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
from _collections import defaultdict
from functools import lru_cache

class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def map_int():
        return [int(x) for x in Scanner.string().split()]
    def string_list(n):
        return [input() for i in range(n)]
    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]
    def int_cols_list(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3,d + 1,2):
            if n % i == 0:
                return False
        return True

MOD = int(1e09) + 7

def main():
    A,B,C,D,E,F = Scanner.map_int()
    n,m = 0,0
    M = 0
    for a in range(41):
        for b in range(41):
            w = A * a * 100 + B * b * 100
            for c in range(41):
                for d in range(41):
                    s = c * C + d * D
                    mass = w + s
                    if mass > F:
                        continue
                    if s * 100 > E * w:
                        continue
                    if s * n >= m * mass:
                        n,m = mass,s

    print(n,m)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,d,e,f = inpl()
water = set()
sugar = set()
for i in range(f//(a*100)+10):
    for j in range(f//(b*100)+10):
        w = a*100*i + b*100*j
        if w > f:
            break
        water.add(w)
for i in range(f//c+10):
    for j in range(f//d+10):
        s = c*i + d*j
        if s > f:
            break
        sugar.add(s)
water = sorted(list(water))
sugar = sorted(list(sugar))
# print(water)
# print(sugar)

max_cons = 0
res_to = a*100
res_s = 0
for w in water:
    for s in sugar:
        if w+s > f:
            break
        if w == 0 and s == 0:
            continue
        cons = s/(w+s)
        # print(w,s)
        if cons > e/(100+e):
            continue
        if cons > max_cons:
            res_to = w+s
            res_s = s
            max_cons = cons
print(res_to,res_s)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c,d,e,f = inpl()
water = set()
sugar = set()
for i in range(f//(a*100)+10):
    for j in range(f//(b*100)+10):
        w = a*100*i + b*100*j
        if w > f:
            break
        water.add(w)
for i in range(f//c+10):
    for j in range(f//d+10):
        s = c*i + d*j
        if s > f:
            break
        sugar.add(s)
water = sorted(list(water))
sugar = sorted(list(sugar))
# print(water)
# print(sugar)

max_cons = 0
res_to = 0
res_s = 0
for w in water:
    for s in sugar:
        if w+s > f:
            break
        if w == 0 and s == 0:
            continue
        cons = s/(w+s)
        # print(w,s)
        if cons > e/(100+e):
            continue
        if cons >= max_cons:
            res_to = w+s
            res_s = s
            max_cons = cons
print(res_to,res_s)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
limit = 100 * e / (100 + e)
mx = -1

waters = set()
for i in range(0, f + 1, 100 * a):
    for j in range(0, f + 1, 100 * b):
        if i + j <= f:
            waters.add(i + j)

sugars = set()
for i in range(0, f + 1, c):
    for j in range(0, f + 1, d):
        if i + j <= f:
            sugars.add(i + j)

for i in waters:
    for j in sugars:
        if i + j <= f and i + j != 0:
            noudo = 100 * j / (i + j)
            if noudo <= limit:
                if noudo > mx:
                    mx = noudo
                    x, y = i + j, j
print(x, y)

Submission status: Accepted

Solution code:
a, b, c, d, e, f = map(int, input().split())
a, b = 100 * a, 100 * b
limit = 100 * e / (100 + e)
mx = -1

for i in range(f // a + 1):
    for j in range((f - i * a) // b + 1):
        for k in range((f - i * a - j * b) // c + 1):
            for l in range((f - i * a - j * b - k * c) // d + 1):
                water = i * a + j * b + k * c + l * d
                sugar = k * c + l * d
                if water > f or water == 0:
                    break
                if (100 * sugar / water) <= limit:
                    if (100 * sugar / water) > mx:
                        mx = (100 * sugar / water)
                        x, y = water, sugar
print(x, y)

Submission status: Accepted

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d,e,f=LI()
  ans_n=-inf
  ans_pair=[0,0]

  z=100*e/(100+e)
  # print(z)
  
  for i in range(31):
    for j in range(31):
      for k in range(3001):
        for l in range(3001):
          _a=a*i*100+b*j*100
          _b=k*c+l*d

          if _a+_b>f:
            break

          if _a+_b==0:
            break

          y=100*_b/(_a+_b)

          if y<=z:
            if ans_n<=y:
              ans_n=y
              ans_pair=[_a+_b,_b]

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

# main()
print(main())

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
A, B, C, D, E, F = map(int, input().split())
wdp = [0] * (F + 1)
sdp = [0] * (F + 1)
wdp[0] = 1
sdp[0] = 1
resa = 100 * A
resb = 0
for i in range(F + 1):
  if i + A * 100 <= F: wdp[i + A * 100] += wdp[i]
  if i + B * 100 <= F: wdp[i + B * 100] += wdp[i]
for i in range(F + 1):
  if i + C <= F: sdp[i + C] += sdp[i]
  if i + D <= F: sdp[i + D] += sdp[i]
for i in range(1, F + 1):
  if sdp[i] == 0: continue
  w = 0
  for j in range(1, F + 1):
    if i + j > F: break
    if wdp[j] == 0: continue
    if i <= j * E // 100:
      w = j
      break
  if w == 0: continue
  #print(i, i + w)
  #print(float(i) / float(i + w))
  if resb / resa < float(i) / float(i + w):
    resb = i
    resa = i + w
print(resa, resb)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
wl=set()
i=0
while i*100*a<=f:
    j=0
    while i*100*a+j*100*a<=f:
        wl.add(i*100*a+j*100*a)
        j+=1
    i+=1
sl=set()
i=0
while i*c<=f:
    j=0
    while i*c+j*d<=f:
        sl.add(i*c+j*d)
        j+=1
    i+=1
max=0
x=0
y=0
for w in wl:
    if w==0:
        continue
    for s in sl:
        if w//100*e>=s and w+s<=f:
            if x==0 and y==0:
                x=w
                y=s
            if max<s/(w+s):
                max=s/(w+s)
                x=w+s
                y=s
print(x,y)

Submission status: Accepted

Solution code:
def main():
    a,b,c,d,e,f = map(int,input().split())
    a*=100
    b*=100
    den=0.0
    x=0
    y=0
    for i in range(f//b+1):
        for j in range((f-(i*b))//a+1):
            for k in range((f-(i*b+j*a))//d+1):
                for l in range((f-(i*b+j*a+k*d))//c+1):
                    if i*b+j*a>0 and f>=i*b+j*a+k*d+l*c and (k*d+l*c)/(i*b+j*a) <= e/100 and den < (k*d+l*c)/(i*b+j*a):
                        den=(k*d+l*c)/(i*b+j*a)
                        x=i*b+j*a+k*d+l*c
                        y=k*d+l*c
    if x==0:
        print(a,0)
    else:
        print(x,y)                  
if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    A, B, C, D, E, F = map(int, input().split())
    waters = set()
    sugars = set()
    for a in range(0, F+1, 100 * A):
        for b in range(0, F+1, 100 * B):
            if a + b <= F:
                waters.add(a + b)
            else:
                break
    for c in range(0, F+1, C):
        for d in range(0, F+1, D):
            if c + d <= F:
                sugars.add(c + d)
            else:
                break
    waters = sorted(list(waters))[1:]
    sugars = sorted(list(sugars))
    # print(sugars)
    ans = 0
    ans_w = 0
    ans_s = 0
    for w in waters:
        for s in sugars:
            if w + s <= F:
                if s <= (w//100) * E:
                    tmp = (100 * s)/(w + s)
                    # if w == 1700:
                        # print(w, s, (100 * s)/(w + s))
                    if tmp >= ans:
                        ans = tmp
                        ans_w = w
                        ans_s = s
            else:
                break
    print(ans_w + ans_s, ans_s)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

x, y, maxe = 0, 0, 0.0

for a in range(F//(A*100)+1):
    for b in range((F-100*A*a)//(B*100)+1):
        for c in range((F-100*(A*a+B*b))//C+1):
            for d in range((F-100*(A*a+B*b)-C*c)//D+1):
                if A*a+B*b == 0:
                    continue
                e = (C*c+D*d) / (A*a+B*b)
                if e <= E and maxe <= e:
                    maxe = e
                    y = C*c+D*d
                    x = 100*(A*a+B*b) + y

print(x, y)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d, e, f = list(map(int, input().rstrip('\n').split()))
    mt = a * 100
    ms = 0
    mn = 0
    for i in range(0, f + 1, a * 100):
        for j in range(0, f - i + 1, b * 100):
            for k in range(0, f - i - j + 1, c):
                for l in range(0, f - i - j - k + 1, d):
                    t = i + j
                    s = k + l
                    if 0 < t + s <= f:
                        if s / (t + s) <= e / (100 + e):
                            if s / (t + s) > mn:
                                mn = s / (t + s)
                                mt = t
                                ms = s
    print(mt + ms, ms)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    a, b, c, d, e, f = list(map(int, input().rstrip('\n').split()))
    abcd = 0
    cd = 0
    md = 0
    for ai in range(0, f + 1, a * 100):
        for bi in range(0, f + 1, b * 100):
            for ci in range(0, f + 1, c):
                for di in range(0, f + 1, d):
                    if 0 < ai + bi + ci + di <= f:
                        if ai + bi != 0:
                            if md < (ci + di) / (ai + bi + ci + di) <= e / (100 + e):
                                md = (ci + di) / (ai + bi + ci + di)
                                abcd = ai + bi + ci + di
                                cd = ci + di
                    else:
                        break
    print(abcd if abcd != 0 else a * 100, cd)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:

from collections import deque, defaultdict
import copy
import bisect
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

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

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

water = [0]*(F//100 + 1)
water[0] = 1
water_list = [0]
for i in range(1, len(water)):
	if A <= i and water[i - A] == 1:
		water[i] = 1
		water_list.append(i*100)
	elif B <= i and water[i - B] == 1:
		water[i] = 1
		water_list.append(i * 100)

suger = [0]*(E*water_list[-1]//100 + 1)
suger[0] = 1
max_n = 0
ws = [A*100, 0]
for i in range(1, len(suger)):
	if C <= i and suger[i - C] == 1:
		suger[i] = 1
	elif D <= i and suger[i - D] == 1:
		suger[i] = 1
	if suger[i] == 1:
		max_s = i*100/E
		loc = bisect.bisect_left(water_list, max_s)
		if loc <= len(water_list) and  water_list[loc] + i <= F:
			if max_n < 100*i/(water_list[loc] + i):
				ws = [water_list[loc], i]
			max_n = max(max_n, 100*i/(water_list[loc] + i))
print(ws[0] + ws[1], ws[1])

Submission status: Accepted

Solution code:
A,B,C,D,E,F=map(int,input().split())
ans={'water':A*100,'suger':0}
def density(water,suger):
    return 100*suger/(water+suger)
for a in range(31):
    for b in range(31):
        water=(a*A+b*B)*100
        if water>F:
            continue
        max_suger=min((a*A+b*B)*E,F-water)
        for c in range(max_suger//C+1):
            suger=c*C
            suger+=((max_suger-suger)//D)*D
            if water+suger==0:
                continue
            elif density(water,suger)>density(ans['water'],ans['suger']):
                ans['water']=water
                ans['suger']=suger
print(ans['water']+ans['suger'],ans['suger'])

Submission status: Accepted

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

mc, mw, ms = 0, 0, 0
for a in range(F // (A * 100) + 1):
    for b in range((F - a * A * 100) // (B * 100) + 1):
        if a == 0 and b == 0:
            continue
        for c in range((F - (a * A + b * B) * 100) // C + 1):
            for d in range((F - (a * A + b * B) * 100 - c * C) // D + 1):
                w, s = (a * A + b * B) * 100, c * C + d * D
                if w + s <= F and w * E >= s * 100 and mc <= s / (w + s):
                    mc, mw, ms = s / (w + s), w, s
print(mw + ms, ms)

Submission status: Accepted

Solution code:
def satou(a,b):
    return 100 * b / (a+b)

a,b,c,d,e,f = map(int,input().split())
water = [-1 for j in range(f+2)]
sugar = [-1 for i in range(f+2)]
water[0] = 0
sugar[0] = 0

for i in range(f+1):
    if water[i] > -1:
        if i+100*a <= f :
            water[i+100*a] = i+100*a 
        if i+100*b <= f :
            water[i+100*b] = i+100*b
    if sugar[i] > -1:
        if i+c <= f :
            sugar[i+c] = i+c
        if i+d <= f :
            sugar[i+d] = i+d
w = list(set(water))
w.remove(-1)
w.remove(0)
s = list(set(sugar))
s.remove(-1)
s.remove(0)
#print(w,s)
mx = 0
ws = [100*a,0]
for i in w:
    for j in s:
        x = ((f-i) // j) * j
        y = ((e*i/100)//j) * j
        t = satou(i, min(x,y))
        if mx < t:
            mx = t
            ws = [i, min(x,y)]

print(int(sum(ws)), int(ws[1]))

Submission status: Accepted

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

tmp = 0
ans = [0,0]
for i in range(31):
  a = A*i
  if a*100 >= F:
    break
  for j in range(31):
    b = B*j
    if a+b == 0:
      continue
    w = (a+b)*100
    if w >= F:
      break
    for k in range(3001):
      c = C*k
      for l in range(3001):
        d = D*l
        s = c+d
        if w + s > F:
          break
        if (c+d) <= (a+b)*E:
          if (s*100)/w >= tmp:
            tmp = (s*100)/w
            ans = [s+w,s]
        else:
          break

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

Submission status: Accepted

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

ans_w = 0
ans_s = 0
max_ans = 0.0
for a in range(31):
    for b in range(31):
        w = 100 * (A * a + B * b)
        if w > F:
            break
        for c in range((w // 100 * E) // C + 1):
            for d in range(((w // 100 * E) - c) // D + 1):
                s = C * c + D * d
                if s > (w // 100 * E) or (w + s) > F:
                    break
                if w + s != 0:
                    n = (100 * s) / (w + s)
                    if n > max_ans:
                        max_ans = n
                        ans_w = w
                        ans_s = s

if ans_w == 0 and ans_s == 0:
    print(100 * A, 0)
else:
    print(ans_w + ans_s, ans_s)

Submission status: Accepted

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

tmp = 0
ans_A = 0
ans_B = 0
for a in range(31):
    for b in range(31):
        x = 100 * (a * A + b * B)
        if x > F:
            break
        for c in range((x // 100 * E) // C + 1):
            for d in range(((x // 100 * E) - c) // D + 1):
                y = c * C + d * D
                if x + y > F or y > x * E // 100:
                    break
                if x + y != 0:
                    if y / (x + y) > tmp:
                        ans_A = x + y
                        ans_B = y
                        tmp = y / (x + y)

if ans_A == 0:
    print(100 * A, 0)
else:
    print(ans_A, ans_B)

Submission status: Accepted

Solution code:
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int e = Integer.parseInt(sc.next());
		int f = Integer.parseInt(sc.next());
		int water = 0;
		int sugar = 0;
		for (int i = 0; i <= f; i += 100 * a) {
			for (int j = 0; i + j <= f; j += 100 * b) {
				for (int k = 0; i + j + k <= f; k += c) {
					for (int l = 0; i + j + k + l <= f; l += d) {
						if ((k + l) * 100 <= e * (i + j)) {
							if ((water == 0 && sugar == 0)|| sugar * (i + j + k + l) < (k + l) * water) {
								water = i + j + k + l;
								sugar = k + l;
							}
						}
					}
				}
			}
		}
		System.out.println(water + " " + sugar);
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Submission status: Accepted

Solution code:
def solve(C, D, lim):
    ans = 0
    for i in range(3000):
        if C*i > lim:
            break
        for j in range(3000):
            eval = C*i + D*j
            if eval > lim:
                break
            elif eval > ans:
                ans = eval
    return ans

A, B, C, D, E, F = map(int,input().split())
# E(A+B) >= C+D, 100A+100B+C+D <= Fを満たす中での(C+D)/(100A+100B+C+D)の最大化
water = [] #ありうる(A, B)の組
waterlen = 0
ans = [0, 0]
noudo = 0
for i in range(30):
    for j in range(30):
        val = 100*A*i + 100*B*j
        if val <= F:
            water.append(val)
            waterlen += 1
        else:
            break
water.pop(0)
waterlen -= 1
for i in range(waterlen):
    sugarlim = min(water[i] // 100 * E, F-water[i])
    sugar = solve(C, D, sugarlim)
    
    val = 100*sugar/(water[i]+sugar)
    if val > noudo:
        noudo = val
        ans[0] = water[i] + sugar
        ans[1] = sugar
if ans[0] == 0 and ans[1] == 0:
    ans[0] = 100*A
print(*ans)

Submission status: Accepted

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

water = set()
sugar = set()

i = 0
while 100*a*i<=f:
    j = 0
    while 100*a*i+100*b*j<=f:
        water.add(100*a*i+100*b*j)
        j+=1
    i+=1

i = 0
while c*i<=f:
    j = 0
    while c*i+d*j<=f:
        sugar.add(c*i+d*j)
        j+=1
    i+=1

sugar.add(0)

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

sugar2 = [0]*(f+1)
for i in range(len(sugar)-1):
    sugar2[sugar[i]:sugar[i+1]] = [sugar[i]]*(sugar[i+1]-sugar[i])

ans = [a*100,0]

for i in range(1,len(water)):
    s = min(f-water[i],water[i]*e//100)
    if ans[1]/ans[0]<sugar2[s]/(water[i]+sugar2[s]):
        ans = [water[i]+sugar2[s], sugar2[s]]

print(ans[0],end=' ')
print(ans[1])

Submission status: Accepted

Solution code:
# ARC083C - Sugar Water (ABC074C)
def main():
    # input
    a, b, c, d, e, f = list(map(int, input().rstrip().split()))
    A = a * 100
    B = b * 100

    # default values
    x, y = min(a, b) * 100, 0  # density may be 0%
    dens = y / x

    # exhaustive search
    for i in range(f // A + 1):
        for j in range(((f - A * i) // B) + 1):
            if i == 0 and j == 0:
                continue
            water = i * A + j * B
            rest = f - water
            for k in range(rest // c + 1):
                for l in range((rest - c * k) // d + 1):
                    sugar = c * k + d * l
                    total = water + sugar

                    if sugar / total > e / (e + 100):  # compare to e (the max density)
                        break
                    else:
                        if sugar / total > dens:
                            dens = sugar / total
                            x, y = total, sugar
    print(x, y)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import product

A, B, C, D, E, F = map(int, input().split())
conc = 0
water, sugar = 100*A, 0
for i, j in product(range(F // (100*A) + 1), range(F // (100*B) + 1)):
    wt = 100*(A*i + B*j)
    if wt > F or wt == 0:
        continue
    rem = F - wt
    for k, l in product(range(rem // C + 1), range(rem // D + 1)):
        sg = C*k + D*l
        sugar_water = wt + sg
        if sg <= wt*E // 100 and 0 < sugar_water <= F:
            temp = 100*sg/sugar_water
            if conc < temp:
                conc = temp
                water, sugar = wt, sg
print(water+sugar, sugar)

Submission status: Accepted

Solution code:
# ARC083C - Sugar Water (ABC074C)
# input
a, b, c, d, e, f = list(map(int, input().rstrip().split()))
A = a * 100
B = b * 100

# default values
x, y = min(a, b) * 100, 0  # density may be 0%
dens = y / x


# exhaustive search
for i in range(f // A + 1):
    for j in range(((f - A * i) // B) + 1):
        if i == 0 and j == 0:
            continue
        water = i * A + j * B
        rest = f - water
        for k in range(rest // c + 1):
            for l in range((rest - c * k) // d + 1):
                sugar = c * k + d * l
                total = water + sugar

                if sugar / total > e / (e + 100):  # compare to e (the max density)
                    break
                else:
                    if sugar / total > dens:
                        dens = sugar / total
                        x, y = total, sugar
print(x, y)

Submission status: Accepted

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

ans = [0,A*100]

for a in range(31):
    for b in range(31):
        if a*A+b*B==0 or a*A+b*B>=F:
            continue
        for c in range((3000//C)+1):
            if c*C>E*(a*A+b*B) or (a*A+b*B)*100+c*C>F:
                continue
            d = min((E*(a*A+b*B)-c*C)//D,(F-((a*A+b*B)*100+c*C))//D)
            if (a*A+b*B)*100+(c*C+d*D)>F or c*C+d*D>(a*A+b*B)*E:
                continue
            ans_tmp = [c*C+d*D,(a*A+b*B)*100]
            if ans_tmp[0]*ans[1] > ans[0]*ans_tmp[1]:
                ans = ans_tmp
print(ans[1]+ans[0],ans[0])

Submission status: Accepted

Solution code:
a,b,c,d,e,f=map(int,input().split())
maxsugar=f*e/(100+e)
maxwater=f*100/(100+e)
#print(maxsugar,maxwater)
sugar=[]
for i in range(int(maxsugar)//min(c,d)+2):
    for j in range(int(maxsugar)//min(c,d)+2):
        x=i*c+j*d
        if x<=maxsugar:
            sugar.append(x)
#print(sugar)
water=[]
for i in range(int(maxwater//100+2)//min(a,b)+2):
    for j in range(int(maxwater//100+2)//min(a,b)+2):
        y=i*a+j*b
        water.append(y)
#print(water)
water.remove(0)
ansl=[]
for i in sugar:
    for j in water:
        z=i/(j*100+i)
        xyz=i+j*100
        if xyz<=f and z<=e/(100+e):
            ansl.append((i,j,z))
s,t,r=sorted(ansl,key=lambda x:x[-1])[-1]
print(s+t*100,s)

Submission status: Accepted

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

maxn = .0
total, sato = 0, 0
for _a in range(0, f+1, 100*a):
  for _b in range(0, f-_a+1, 100*b):
    if _a == 0 and _b == 0:
      continue
    for _c in range(0, f-_a-_b+1, c):
      for _d in range(0, f-_a-_b-_c+1, d):
        if ((_a + _b) // 100) * e < _c + _d:
          break
        if 100 * (_c + _d) / (_a + _b + _c + _d) >= maxn:
          maxn = 100 * (_c + _d) / (_a + _b + _c + _d)
          total = _a + _b + _c + _d
          sato = _c + _d
print(total, sato)

Submission status: Accepted

Solution code:
a,b,c,d,e,f=[int(i) for i in input().split(' ')]
ans = -1.0
maxx = 0
maxy = 0
for i in range(0, 31):
  for j in range(0, 31):
    if i * a * 100 + j * b * 100 > f:
      continue
    for k in range(0, 3001):
      if i * a * 100 + j * b * 100 + k * c > f:
        continue
      for l in range(0, 3001):
        if i * a * 100 + j * b * 100 + k * c + l * d > f:
          continue
        if (i * a + j * b) * e < k * c + l * d:
          continue
        x = 100 * a * i + 100 * b * j
        y = k * c + l * d
        if (not x + y == 0) and (x + y) * ans < y:
          ans = max(ans, y / (x + y))
          maxx = x
          maxy = y
print(maxx + maxy, maxy)

Submission status: Accepted

Solution code:
import fractions as frac
a, b, c, d, e, f = map(int, input().split())
memo=[[(-1, -1)]*1000 for i in range(10000)]
func = lambda t: frac.Fraction(t[0], t[1]) if t[1]>0 else -10
def dp(s, w):
    if w*e<s or w*100+s>f:
        return (-1, -1)
    m=memo[s][w]
    if m[0]>0:
        return m
    p0=(s,w) 
    p1=dp(s, w+a)
    p2=dp(s, w+b)
    p3=dp(s+c, w)
    p4=dp(s+d, w)
    memo[s][w]=max(p0, p1, p2, p3, p4, key = func) if w>0 else max(p1, p2, key = func)
    return memo[s][w]
    
ans=dp(0,0)
print(ans[0]+ans[1]*100, ans[0])

Submission status: Accepted

Solution code:
A,B,C,D,E,F = map(int, input().split())
ans = {"w":A*100, "s":0}
def density(water, sugar):
    return 100*sugar/(water+sugar)

for a in range(31):
    for b in range(31):
        water = (a*A+b*B)*100
        if water>F:
            continue
        max_sugar = min((a*A+b*B)*E, F-water)
        for c in range(max_sugar//C+1):
            sugar = c*C
            sugar += ((max_sugar-sugar)//D)*D
            if water+sugar==0: 
                continue
            if density(water, sugar)>density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
print(ans["w"]+ans["s"], ans["s"])

Submission status: Accepted

Solution code:
from fractions import gcd
def solve():
    A,B,C,D,E,F = map(int, input().split())
    ans = {"w":A*100, "s":0}
    def density(water, sugar):
        return 100*sugar/(water+sugar)

    G = gcd(C,D)
    for a in range(31):
        for b in range(31):
            water = (a*A+b*B)*100
            if water>F:
                continue
            max_sugar = min((a*A+b*B)*E, F-water)
            sugar = int(G*(max_sugar//G))
            if sugar<min(C,D): continue
            if water+sugar==0: 
                continue
            if density(water, sugar)>density(ans["w"], ans["s"]):
                ans["w"] = water
                ans["s"] = sugar
                #print(water, sugar)
    print(ans["w"]+ans["s"], ans["s"])
    
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from fractions import gcd
A,B,C,D,E,F = map(int, input().split())
ans = {"w":A*100, "s":0}
def density(water, sugar):
    return 100*sugar/(water+sugar)

G = gcd(C,D)
for a in range(31):
    for b in range(31):
        water = (a*A+b*B)*100
        if water>F:
            continue
        max_sugar = min((a*A+b*B)*E, F-water)
        sugar = int(G*(max_sugar//G))
        if sugar<min(C,D): continue
        if water+sugar==0: 
            continue
        if density(water, sugar)>density(ans["w"], ans["s"]):
            ans["w"] = water
            ans["s"] = sugar
            #print(water, sugar)
print(ans["w"]+ans["s"], ans["s"])