Final Discount Price A shopkeeper has a sale to complete and has arranged the items being sold in an array. Starting from the left, the shopkeeper sells each item at its full price minus the price of the first lower or equal priced item to its right. If there is no item to the right that costs less than or equal to the current item's price, the current item is sold at full price. For example, assume there are items nriced [? 3. 1 24 21

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
+ ||
* 00
< CO
Final Discount Price
A shopkeeper has a sale to complete and has arranged the items being sold in an array. Starting from the left, the shopkeeper sells each item at its full
price minus the price of the first lower or equal priced item to its right. If there is no item to the right that costs less than or equal to the current item's
price, the current item is sold at full price.
For example, assume there are items priced [2, 3, 1, 2, 4, 2]
• The items 0 and 1 are each discounted by 1 unit, the first equal or lower price to the right
• Item 2, priced 1 unit sells at full price because there are no equal or lower priced items to the right
• The next item, item 3 at 2 units, is discounted 2 units, as would the item 4 at 4 units
• The final item 5 at 2 units must be purchased at full price because there are no lower prices to the right
The total cost is 1+2+1+0+2+2=8units. The full price items are at indices [2, 5] using Obased indexing.
You have to print the sum of the final prices.
Input Format
The first line of input contains T, the number of test cases. In the next T lines:
• Each line contains n followed by n elements of the array
Output Format
• Print T lines with the sum of the final prices
Your Answer
Language
Report I
MacBook Air
08
DD
F7
F2
F3
F4
F5
F6
F8
F10
|
#3
%
$
3.
4.
R
}
M
A
F
K
1
option
otion
command
command
Transcribed Image Text:+ || * 00 < CO Final Discount Price A shopkeeper has a sale to complete and has arranged the items being sold in an array. Starting from the left, the shopkeeper sells each item at its full price minus the price of the first lower or equal priced item to its right. If there is no item to the right that costs less than or equal to the current item's price, the current item is sold at full price. For example, assume there are items priced [2, 3, 1, 2, 4, 2] • The items 0 and 1 are each discounted by 1 unit, the first equal or lower price to the right • Item 2, priced 1 unit sells at full price because there are no equal or lower priced items to the right • The next item, item 3 at 2 units, is discounted 2 units, as would the item 4 at 4 units • The final item 5 at 2 units must be purchased at full price because there are no lower prices to the right The total cost is 1+2+1+0+2+2=8units. The full price items are at indices [2, 5] using Obased indexing. You have to print the sum of the final prices. Input Format The first line of input contains T, the number of test cases. In the next T lines: • Each line contains n followed by n elements of the array Output Format • Print T lines with the sum of the final prices Your Answer Language Report I MacBook Air 08 DD F7 F2 F3 F4 F5 F6 F8 F10 | #3 % $ 3. 4. R } M A F K 1 option otion command command
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY