COM. Assume you want to build a program to help drivers maximize their income based on the loads they carry on a daily basis. Consider that we have n days of data where each day i allows a truck to carry a load. The truck driver has two choices: a light or a heavy load. The truck driver will get paid the amount of Li in case the driver selects a light load on day i. Alternatively, the driver will get paid Hi in case of selecting a heavy load on day i. The driver cannot carry more than one load per day. Also, if the driver selects to carry a heavy load, the driver is not allowed to carry any load the day before. Your goal is to maximize the driver’s income. Write the MaxDriverPay(int N, int* L, int * H) function which takes three inputs: N (1≤N) which represents the number of days L which represents an array of N values where each Li value represents the payment of day i in case light load is selected that day H which represents an array of N values where each Hi value represents the payment of day i in case heavy load is selected that day Day 1 2 3 .. n Light load L1 L2 L3 .. Ln Heavy load H1 H2 H3 .. Hn Output As a result, your function should return the maximum payment the driver can get based on the given input Example 1: N=40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 Result is 61 Explanation: The best is to start with a high load, then you will carry a high load every other day, you will have 20 heavy loads (20*3) + 1 light load at the end = 61 Example 2: N=3 5 5 5 2 7 6 Result is 15 Explanation: Better to pick all light loads, the total will be 15, because if we pick any of the heavy loads, we can use the load from the day before which means we cannot be higher than 15 total
COM.
Assume you want to build a
Write the MaxDriverPay(int N, int* L, int * H) function which takes three inputs:
N (1≤N) which represents the number of days
L which represents an array of N values where each Li value represents the payment of day i in case light load is selected that day
H which represents an array of N values where each Hi value represents the payment of day i in case heavy load is selected that day
Day 1 2 3 .. n
Light load L1 L2 L3 .. Ln
Heavy load H1 H2 H3 .. Hn
Output
As a result, your function should return the maximum payment the driver can get based on the given input
Example 1:
N=40
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Result is 61
Explanation:
The best is to start with a high load, then you will carry a high load every other day, you will have 20 heavy loads (20*3) + 1 light load at the end = 61
Example 2:
N=3
5 5 5
2 7 6
Result is 15
Explanation:
Better to pick all light loads, the total will be 15, because if we pick any of the heavy loads, we can use the load from the day before which means we cannot be higher than 15 total
Trending now
This is a popular solution!
Step by step
Solved in 2 steps