This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Risinājums sliktākajā gadījumā strādā lineāri rožu skaitam buķetēs.
#include <fstream>
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
template<class T>
T gcd(T a, T b)
{
T c = a % b;
while(c > 0){
a = b;
b = c;
c = a % b;
}
return b;
}
int main()
{
long long int A,B,C,D,N;
//ifstream in("rozes.dat");
cin >> N >> A >> B >> C >> D ;
//in.close();
if(B*C > D*A)
{
swap(A, C);
swap(B, D);
}
long long ans = (N + A-1)/A*B;
long long n = A/gcd(A, C);
for(long long i = 1; i < n; i++)
{
long long t = i*D;
if(N - C*i > 0) t+= (N - C*i + A-1)/A * B;
ans = min(ans, t);
}
//ofstream out("rozes.rez");
cout<<ans<<endl;
//out.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |