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

Solution in C# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var r = ReadLine().Split().Select(int.Parse).ToArray();
        int A = r[0], B = r[1], C = r[2], D = r[3], E = r[4], F = r[5];
        var dp = new (double, double)[F+1];//水　砂糖
        for (int i = 0; i < F+1; i++)
        {
            dp[i] = (-1,0);
        }
        dp[0] = (0, 0);
        for (int i = 0; i < F+1; i++)
        {
            if (dp[i].Item1 != -1)
            {
                var nxt = i + 100 * A;
                if (nxt > F) continue;
                dp[nxt] = (nxt, 0);
            }
        }
        for (int i = 0; i < F + 1; i++)
        {
            if (dp[i].Item1 != -1)
            {
                var nxt = i + 100 * B;
                if (nxt > F) continue;
                dp[nxt] = (nxt, 0);
            }
        }
        for (int i = 0; i < F+1; i++)
        {
            if (dp[i].Item1 != -1)
            {
                var nxt = i + C;
                var (a, b) = dp[i];
                if (nxt > F) continue;
                if (b + C > a / 100 * E) continue;
                if (dp[nxt].Item2 > 0)
                {
                    dp[nxt] = (a, Max(b + C,dp[nxt].Item2));
                }
                else
                {
                    dp[nxt] = (a, b + C);
                }
            }
        }
        for (int i = 0; i < F + 1; i++)
        {
            if (dp[i].Item1 != -1)
            {
                var nxt = i + D;
                var (a, b) = dp[i];
                if (nxt > F) continue;
                if (b + D > a / 100 * E) continue;
                if (dp[nxt].Item2 > 0)
                {
                    dp[nxt] = (a, Max(b + D, dp[nxt].Item2));
                }
                else
                {
                    dp[nxt] = (a, b + D);
                }
            }
        }
        double max = 0;
        var ans = new int[2];
        for (int i = 0; i < F+1; i++)
        {
            if (dp[i].Item1 != -1)
            {
                var (a, b) = dp[i];
                double p = 100 * b / (a + b);
                if (max < p)
                {
                    ans = new int[2] { (int)(a+b), (int)b };
                    max = p;
                }
            }
        }
        WriteLine(string.Join(" ",ans));
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[0], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[0], typeof(T4));
        return (r1, r2, r3, r4);
    }
}