This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Segment Tree Degil Bu What
#include "bits/stdc++.h"
using namespace std;
#define ll long long
const ll MOD = 1e9+7;
const ll MAX = 2e5+1;
void solve(){
ll n,a,b,c,d;
cin>>n>>a>>b>>c>>d;
ll ans1 = 0, ans2 = 0;
long double first = ((long double)b)/a, second = ((long double)d)/c;
if(first > second){
ans1 = (n / c) * d;
n-=((n / c) * c );
if(n == 0){
cout<<ans1;
return;
}
ans2 = ans1;
ans1 += d;
ans2 += (n / a) * b;
n-= (n / a) * a;
if(n != 0){
ans2+= b;
}
cout << min(ans1,ans2);
}else{
ans1 = (n / a) * b;
n-=((n / a) * b );
if(n == 0){
cout<<ans1;
return;
}
ans2 = ans1;
ans1 += b;
ans2 += (n / c) * d;
n-= (n / c) * c;
if(n != 0){
ans2+= d;
}
cout << min(ans1,ans2);
}
}
int main()
{
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |