-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheap-Travels.c
40 lines (36 loc) · 965 Bytes
/
Cheap-Travels.c
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
#include <stdio.h>
#include <math.h>
int main()
{
int plannedRide, specialRide, oneRidePrice, specialRidePrice, minimumCost = 0;
scanf("%d %d %d %d", &plannedRide, &specialRide, &oneRidePrice, &specialRidePrice);
if(specialRide >= plannedRide)
{
if(plannedRide * oneRidePrice < specialRidePrice)
{
minimumCost = plannedRide * oneRidePrice;
}
else
{
minimumCost = specialRidePrice;
}
}
else
{
int specialRideTaken = plannedRide / specialRide;
int rideLeft = plannedRide - (specialRideTaken * specialRide);
minimumCost = (rideLeft * oneRidePrice) + (specialRideTaken * specialRidePrice);
int onlyOneRideCost = plannedRide * oneRidePrice;
int onlySpecialCost = ceil(plannedRide/(double)specialRide) * specialRidePrice;
if(onlyOneRideCost < minimumCost)
{
minimumCost = onlyOneRideCost;
}
if(onlySpecialCost < minimumCost)
{
minimumCost = onlySpecialCost;
}
}
printf("%d\n", minimumCost);
return 0;
}