Maximum Profit on App
You have made a smartphone app and want to set its price such that the profit earned is maximised. There are certain buyers who will buy your app only if their budget is greater than or equal to your price.
You will be provided with a list of size N having budgets of buyers and you need to return the maximum profit that you can earn.
Lets say you decide that price of your app is Rs. x and there are N number of buyers. So maximum profit you can earn is :
where m is total number of buyers whose budget is greater than or equal to x.
Input format :
Output Format :
Constraints :
1 <= N <= 10^6
Sample Input 1 :
Sample Output 1 :
Sample Output 1 Explanation :
Price of your app should be Rs. 20 or Rs. 30. For both prices, you can get the profit Rs. 60.
Sample Input 2 :
Sample Output 2 :
Sample Output 2 Explanation :
Price of your app should be Rs. 67. You can get the profit Rs. 201 (i.e. 3 * 67).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num=int(input()) | |
arr= list(map(int,input().split())) | |
m=0 | |
arr.sort() | |
for i in arr: | |
if m<i*num: | |
m=i*num | |
num=num-1 | |
print(m) |
Comments
Post a Comment
Please give us your valuable feedback