This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
     
        ll n;
        int a, b, c, d;
        cin >> n >> a >> b >> c >> d;
     
        ll ans = 1e18;
     
        auto calculate1 = [&](int c1) -> ll {
            ll c2 = max(0ll, n - c1 * a + c - 1) / c;
            return c1 * b + c2 * d;
        };
     
        auto calculate2 = [&](int c1) -> ll {
            ll c2 = max(0ll, n - c1 * c + a - 1) / a;
            return c1 * d + c2 * b;
        };
     
        for(int i = 0; i <= min(ll(1e5), n); i++) {
            ans = min(ans, calculate1(i));
            ans = min(ans, calculate2(i));
        }
     
        cout << ans;
     
        return 0;
    }
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |