Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java code please. ------------------------------------------------------------------- ****** Java code, please******* Program 2: There are N cities in a country. These cities are on a straight road. For

Java code please.

image text in transcribed

-------------------------------------------------------------------

******Java code, please*******

Program 2: There are N cities in a country. These cities are on a straight road. For convenience, let's put a straight line in the horizontal direction. Dr. Kim wants to travel by car from the far left city to the far right city. The roads between two neighboring cities may have different lengths. The unit of road length is km. At the start of the car, there is no gas in the car, so you should start with the gas at the gas station We assume that the size of the gas tank is unlimited, so you can put as much gas as you want. When traveling on the road, use 1 liter of gas per km. There is only one gas station in each city, and the price per liter of gas station may vary from city to city. Unit of price uses US dollar. 2 3 5 4 1 For example, suppose there are four cities in this country, as shown in the following figure. The number in the circle is the price per liter of the gas station in the city. The numbers above the road indicate the length of the road in km In the leftmost city, we put 6 liter of gas and can move to the rightmost city without buying gas any more. The total cost is $30 Write a program that calculates the minimum cost of moving from the leftmost city to the rightmost city. Input format T (number of test case) N (number of city) L1 L2 LN-1 (distance between two adjacent cities) G1 G2 G (Gas price per city) Output format P (total cost to travel from leftmost city to rightmost city) Exampl Input 2 3 1 5 2 4 1 3 3 4 Output 18 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions