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++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define pa pair<int, int>
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define COUT(v)                              \
    for (int64_t i = 0; i < (v).size(); ++i) \
    {                                        \
        cout << v.at(i) << endl;             \
    }
#define REP(i, n) for (int64_t i = 0; i < n; ++i)
#define FOR(i, r, n) for (int64_t i = (r); i < n; ++i)
#define VIN(v)                               \
    for (int64_t i = 0; i < (v).size(); ++i) \
    {                                        \
        cin >> (v).at(i);                    \
    }
 
typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<vector<pa> > pamat;
typedef vector<pali> palivec;
typedef vector<pal> palvec;
 
typedef vector<vector<bool> > bmat;
typedef vector<vector<int> > imat;
typedef vector<vector<long long> > lmat;
 
typedef vector<string> svec;
typedef vector<vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const ll MOD = 1000000007;
 
ll gcd(ll x, ll y)
{
    ll r = x % y;
    if (r == 0)
        return y;
    else
        return gcd(y, r);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}
 
lvec mfactor(ll n)
{
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0] = false;
    ip[1] = false;
    mf[0] = 0;
    mf[1] = 1;
    REP(i, n)
    {
        if (ip[i])
        {
            mf[i] = i;
            for (ll j = i * i; j < n; j += i)
            {
                ip[j] = false;
                if (mf[j] == -1)
                    mf[j] = i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf)
{
    palivec plist;
    while (n != 1)
    {
        int cnt = 0;
        ll m = mf[n];
        while (mf[n] == m)
        {
            cnt++;
            n /= m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}
 
void COMinit(int m, lvec &fac, lvec &finv)
{
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
 
    }
}
 
ll pow_mod(ll a, ll n)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = x * a % MOD;
        }
        a = a * a % MOD;
        n >>= 1;
    }
    return x;
}
 
 
ll COM(int n, int k, const lvec &fac, const lvec &finv)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;
}

ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

typedef map<ll, double> Prob;

void calc(Prob &firsts, Prob &seconds, Prob &thirds){
    vector< pair<double, lvec> > pr;
    for (auto fv: firsts){        
        for (auto sv: seconds){
            for (auto tv: thirds){
                if(fv.first == sv.first || sv.first == tv.first || fv.first == tv.first) continue;
                lvec s(3);
                s[0] = (fv.first);
                s[1] = (sv.first);
                s[2] = (tv.first);
                double p = fv.second*sv.second*tv.second;
                pr.pb( pair<double, lvec >(p, s));
            }
        }
    }

    sort(pr.begin(), pr.end(), greater<pair<double, lvec> >());
    for (auto v: pr){
        cout << "prob: " <<  v.first << " : odds : " << 1/v.first << " : ";
        for (auto vv: v.second){
            cout << vv << ' ';
        }
        cout << endl;
    }
}

ll cnt(ll x){
    ll s = 0;
    ll k = 26;
    for (int i=0; i<x; i++){
        s = s + k;
        k *= 26;
    }
    return s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    ll ma = f/(100*a) + 1;
    ll mb = f/(100*b) + 1;
    pal ans(0, 0);
    pal s(-1, 1);
    for (int i=0; i<ma; i++){
        if(100*a*i > f) break;
        for (int j=0; j<mb; j++){
            ll w = 100*(a*i + b*j);
            if(w > f) break;
            ll mm = min(e*w/100, f-w);
            ll mc = mm/c + 1;
            for (int k=0; k<mc; k++){
                if(k*c > mm) break;
                ll md = (mm - k*c)/d + 1;
                ll ok = 0, ng = md;
                while(ng - ok > 1){
                    ll t = (ng+ok)/2;
                    if(t*d + k*c > mm) {
                        ng = t;
                    }
                    else ok = t;
                }
                ll ws = ok*d + k*c;
                if(s.first*w < ws*s.second){
                    s.first = ws;
                    s.second = w;
                    ans = pal(w + ok*d + k*c, ok*d + k*c);
                }                
            }                        
        }
    }
    cout << ans.first << ' ' << ans.second << endl;





}