Miss Ural wants to buy colors for Holi, and that too, at the cheapest cost!
There are N shops selling colors near Ural's house, where the i′th shop sells colors at rate of Ri for one unit. Also, i′th shop is located at a distance of Di kilometers from her house. Life was simple, but then petrol and fuel prices soared up. The current price of petrol to travel one kilometer is K
Find the minimum cost at which Miss Ural can buy one unit of color. she does not need to return back home.
For test case, output minimum cost to purchase 1 unit of color.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int testcases = 0, price = 0, distance = 0, number = 0;
printf("%s", "Enter testcases: ");
scanf_s("%d", &testcases);
int most_sum = 0;
for (int i = 0; i != testcases; ++i)
{
printf("%s", "Enter shops and prices: ");
scanf_s("%d %d", &number, &price);
int* arr = (int*)malloc(number * sizeof(int));
int cheapest = 50000000;
for (int j = 0; j != number; ++j)
{
printf("%s %d", "Enter distance for shop : ", j + 1);
scanf_s("%d", &arr[j]);
int cheap = arr[j] * price;
if (cheap < cheapest)
{
cheapest = cheap;
}
}
printf("%s %d", "The cheapest price is : ", cheapest);
free(arr);
}
return 0;
}
Comments
Leave a comment