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 <stdio.h>
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
long long mult(long long a, long long b) { return a <= INF / b ? a * b : INF; }
int main() {
long long n, ans;
int a, b, c, d, k, tmp;
scanf("%lld%d%d%d%d", &n, &a, &b, &c, &d);
if (b * c < d * a)
tmp = a, a = c, c = tmp, tmp = b, b = d, d = tmp;
ans = min(mult(b, (n + a - 1) / a), mult(d, (n + c - 1) / c));
for (k = 1; k < c && a < n / k; k++)
ans = min(ans, mult(b, k) + mult(d, (n - a * k + c - 1) / c));
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
Roses.c: In function 'main':
Roses.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%lld%d%d%d%d", &n, &a, &b, &c, &d);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |