-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheap travel.cpp
More file actions
52 lines (49 loc) · 906 Bytes
/
Copy pathCheap travel.cpp
File metadata and controls
52 lines (49 loc) · 906 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
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
int main()
{
int n,m,a,b,x,y,z,rubles_1,rubles_2;
while(scanf("%d %d %d %d",&n,&m,&a,&b)==4){
if(b>a){
if(m>n){
rubles_1=b;
rubles_2=n*a;
}
else{
rubles_1=n*a;
x=n/m;
y=n%m;
z=x*b;
rubles_2=z+(y*a);
}
}
else if(a==b){
x=n/m;
y=n%m;
z=x*b;
if(y==0){
rubles_1=z;
rubles_2=n*a;
}
else{
rubles_1=z+b;
rubles_2=n*a;
}
}
else{
x=n/m;
y=n%m;
z=x*b;
if(y==0){
rubles_1=n*a;
rubles_2=z;
}
else{
rubles_1=n*a;
rubles_2=z+b;
}
}
if(rubles_1<rubles_2)printf("%d\n",rubles_1);
else printf("%d\n",rubles_2);
}
return 0;
}