Dsa
Greedy
Medium
Minimize Gasoline Cost for Delivery Routes
You are planning a delivery route across several cities, and each city charges a different price for gasoline. Given the distances to the cities and their respective gasoline prices, calculate the minimum total cost of gasoline required to reach each city. Each city must be visited exactly once, starting from the first city. The total distance to reach the next city is the difference in indices multiplied by the distance metric. You can assume the starting city is at index 0 and is already paid for.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of cities.
- The second line contains n integers d_1, d_2, ..., d_n (1 ≤ d_i ≤ 100), representing the distance to each city from the previous one.
- The third line contains n integers p_1, p_2, ..., p_n (1 ≤ p_i ≤ 100), representing the gasoline price in each city.
Output format:
- Print a single integer, the minimum total cost of gasoline.
Example:
Input:
3
5 10 15
2 3 1
Output:
50
Key concepts
greedysortingarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now