ZS Coding Question – Solved

9 Live
1. Maximize the Revenue There are n different types of items in a shop, where the number of items of type i is given by quantity[i]. The price of the items is determined dynamically, where the price of the ith item is equal to the remaining number of items of type i. There are m customers in line, and each customer will buy exactly one item of any type. The shopkeeper aims to maximize revenue by selling items optimally. Determine the maximum revenue the shopkeeper can earn by selling exactly m items. Example: Consider n = 3, m = 4, quantity = [1, 2, 4]. One of the optimal ways to sell the items is as follows: The maximum possible revenue is 14. Function Description: Complete the function `getMaximumAmount` with the following parameters: - int quantity[n]: the number of items Returns: - long_int: the maximum revenue possible Constraints: - 1 ≤ n ≤ 10^5 - 1 ≤ m ≤ 10^5 - 1 ≤ quantity[i] ≤ 10^5 Input Format for Custom Testing: Sample Case 0 Sample Input 0 (STDIN): 5 10 10 8 9 1 8 Explanation: quantity[], n = 5 quantity = [10, 10, 8, 9, 1] m = 8 Sample Output 0: 77

Asked in: ZS

Image of the Question

Question Image Question Image Question Image

All Testcases Passed ✔



Passcode Image

Solution


import heapq
def getMaximumAmount(quantity, m):
    # Write your code here
    q = [-i for i in quantity]
// ... rest of solution available after purchase

🔒 Please login to view the solution

Explanation


No explanation available for this question.


Related Questions