y in both the shops. She needs to buy N items in all. And each she ny one of the shops. All the shops offer certain offer. If she buys t p, she gets a offer coupon for the i+1th item in the same shop. But i+1th item from a different shop, she cannot use the offer coupon. example, if she buys the th item in Shop j and gets a offer of X po +1th item be Y pounds in shop j and Z pounds in shop k. If she pur i+1th item from shop j she can use the offer coupon and hence, wi ounds. If she purchases the i+1th item from shop k she cannot use | hence, will have to pay Z pounds. ce: If the offer given is more than price of the item in the shop, i.e. iven free but she does NOT get any moneu hack

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 19PE
icon
Related questions
Question

Here is the detailed and simplified python code for the given question:

Example: Code the given problem using python
Donna likes to shop online. The main reason is that she gets a lot of offer! There
are M online shops from where she purchases her items. The prices of the same item
vary in both the shops. She needs to buy N items in all. And each she can buy each item
in any one of the shops. All the shops offer certain offer. If she buys the h item in one
shop, she gets a offer coupon for the i+ 1th item in the same shop. But if she purchases
the i+1th item from a different shop, she cannot use the offer coupon.
For example, if she buys the th item in Shop j and gets a offer of X pounds. Let the price
of i+1th item be Y pounds in shop j and Z pounds in shop k. If she purchases
the i+1th item from shop j she can use the offer coupon and hence, will have to pay Y-
X pounds. If she purchases the i+1th item from shop k she cannot use the offer coupon
and hence, will have to pay Z pounds.
Note: If the offer given is more than price of the item in the shop, i.e. if Y-X < 0, the item
is given free but she does NOT get any money back.
Donna wants to spend as less as possible and wants your help. She starts buying from
item 1 and goes on till item N in that order. Your task is simple. Tell her the least amount
to spend to get all the N items.
Input:
1
24
1234
4321
2321
1211
Output:
Transcribed Image Text:Example: Code the given problem using python Donna likes to shop online. The main reason is that she gets a lot of offer! There are M online shops from where she purchases her items. The prices of the same item vary in both the shops. She needs to buy N items in all. And each she can buy each item in any one of the shops. All the shops offer certain offer. If she buys the h item in one shop, she gets a offer coupon for the i+ 1th item in the same shop. But if she purchases the i+1th item from a different shop, she cannot use the offer coupon. For example, if she buys the th item in Shop j and gets a offer of X pounds. Let the price of i+1th item be Y pounds in shop j and Z pounds in shop k. If she purchases the i+1th item from shop j she can use the offer coupon and hence, will have to pay Y- X pounds. If she purchases the i+1th item from shop k she cannot use the offer coupon and hence, will have to pay Z pounds. Note: If the offer given is more than price of the item in the shop, i.e. if Y-X < 0, the item is given free but she does NOT get any money back. Donna wants to spend as less as possible and wants your help. She starts buying from item 1 and goes on till item N in that order. Your task is simple. Tell her the least amount to spend to get all the N items. Input: 1 24 1234 4321 2321 1211 Output:
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Computational Systems
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning