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 <iostream>
#define int long long
using namespace std;
int n, a, b, c, d;
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
signed main() {
cin >> n >> a >> b >> c >> d;
if (b * c > d * a) {
swap(a, c);
swap(b, d);
}
int answer = (n + a - 1) / a * b;
int aux = a / gcd(a, c);
for (int i = 1; i <= aux - 1; i++) {
int cost = i * d;
if (n - c * i > 0) {
cost += (n - c * i + a - 1) / a * b;
}
answer = min(answer, cost);
}
cout << answer;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |