-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheapTravel.cpp
More file actions
41 lines (37 loc) · 777 Bytes
/
cheapTravel.cpp
File metadata and controls
41 lines (37 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
int minimum (int a,int b){
if(a>=b) return b;
else if(a<b) return a;
}
int main()
{
int n,m,a,b;
cin>>n>>m>>a>>b;
if(float(b/m)==float(a)){
cout<<a*n;
return 0;
}
else if(float(b/m)>float(a)){
cout<<a*n;
return 0;
}
else if(float(b/m)<float(a)){
if(n%m==0){
int x = n/m;
cout<<x*b;
return 0 ;
}
else if(n%m!=0){
int y = n/m;
int fare1 = y*b;
int remrides = n - m*y;
int fare2 = remrides*a;
int fare3 = b;
int finalfare2 = minimum(fare2,fare3);
cout<<fare1+finalfare2;
return 0;
}
}
return 0;
}