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>
#define ll long long
using namespace std;
const ll lim = 1e16;
ll N, A, B, C, D;
int main(){
cin>>N>>A>>B>>C>>D;
if((double)D/(double)C<(double)B/(double)A){
swap(A, C);
swap(B, D);
}
ll res = ((N+A-1)/A)*B;
ll n = A/__gcd(A,C);//LCM/C - maximum number of times that second buquet can appear
for(int i=1;i<=n;i++){
ll new_res = 0;
new_res += i*D;
ll left = N-(i*C);
if(left>0)
new_res += ((left+A-1)/A)*B;
res = min(res, new_res);
}
cout<<res<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |