#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
ll lcm(ll a, ll b){
return (a * b / __gcd(a,b));
}
int main(){
ll n, a, b, c, d;
cin>>n>>a>>b>>c>>d;
ll t = lcm(a, c);
ll ans = 0;
if((t/a)*b <= (t/c)*d){
ll can = n / a;
ans += can * b;
n -= can * a;
ll canA = n / a;
if(n % a != 0)
canA++;
ll canC = n / c;
if(n % c != 0)
canC++;
if(canA * b < canC * d){
ans += canA * b;
}
else
ans += canC * d;
}
else{
ll can = n / c;
ans += can * d;
n -= can * c;
ll canA = n / a;
if(n % a != 0)
canA++;
ll canC = n / c;
if(n % c != 0)
canC++;
if(canA * b < canC * d){
ans += canA * b;
}
else
ans += canC * d;
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |