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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Lower bounds sorting algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education