Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Profits A shopkeeper has the option to buy N items from the producer, the i a of which costs cost i . He can

1 Profits
A shopkeeper has the option to buy N items from the producer, the ia of which costs cost i. He can sell the ith item at sell i, Initially, he has K rupees and 0 items in his shop. At any moment his store can accommodate at most 1 item, which means he has to sell the previous item before buying the next one from the producer.
What is the maximum profit he can achieve?
Notes
He can buy and sell any number of items.
He can use the profit previously earned to buy new items.
One item can be bought and sold atmost once.
Items can be bought and sold in any order and not necessarily in the order given as input.
Function description :
Complete the function solution() provided in the editor. The function takes the following 4 parameters and returns the solution:
N. Represents the number of items
. Represents the initial amount
cost: Represents the cost price of items
selt. Represents the selling price of items
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code
The first line contains N denoting the number of items.
The second line contains K denoting the initial amount.
The third line contains cost denoting the cost price of items.
The fourth line contains sell denoting the selling price of items.
Output format
Print an integer, rebresenting the maximum total profit:
image text in transcribed

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

Group Size and Communication

Answered: 1 week ago

Question

Understanding Group Roles

Answered: 1 week ago