Hai, I am unable to understand the test cases of the question

For instance, suppose you have 4 potential customers and their budgets are 30, 20, 53 and 14. In this case, the maximum revenue you can get is 60.

how can be 60 ? why not 30+53 = 83 ?

Hai, I am unable to understand the test cases of the question

For instance, suppose you have 4 potential customers and their budgets are 30, 20, 53 and 14. In this case, the maximum revenue you can get is 60.

how can be 60 ? why not 30+53 = 83 ?

2 Likes

No. What is your price then?. We price the phone at 30, and 2 people have a budget higher than 30 so we get 30*2=60.

Please specify the problem link

revenue is the total earning not the profit. you have to fix a price suppose you fix a price at 50 then how 30 will buy it only 54 will buy .so revenue is 54 only . but if its price is 30 both will buy at 30 so total revenue is 30+30=60

1 Like

hey here is the explaination

if he decided the price is 14 the all the customer can buy it so the revenue is 14 multiply 4=56

and if he decide the price is 20 so customer with 14 isn’t able to buy it so the revenue is 20 multiply 3=60

and if he decided the price is 30 so only 30 and 53 are able to buy it so the revenue is 30 multiply 2=60

and if he decided the price is 53 so the revenue is 53*1=53 because only customer with price 53 is able to buy it

so the maximum amongst all is 60

hope you understand the concept

let me know if you have any doubt

17 Likes

Thank you I understood the problem now.

1 Like

let take the example of test input 2

5

40

3

65

33

21

if i decided the price 3 the all the customer can buy it so the revenue if 3 multiply 5=15

if i decided the price is 21 then 3 isn’t able to buy so the total number of customer which are able to buy are 4 so 21 multiply 4=84

if i decided the price is 33 the only 3 customer are able to buy 33,40,65 then revenue is 33 multiply 3=99

if i decided the price is 40 then only two customer are able to buy 40,65 then the revnue is 40 multiply 2=80

if i decided the price is 65 then only one customer is able to buy so 65 multiply 1=65

so the maximum revenue is 99

i hope it helps you

1 Like

You need to focus on the constraints given in the problem the value v[ i ] can range upto 10^8. So if you multiply max value of N 5x10^5 then it exceeds the limit of integer(10^9). I suggest you use long long data type

First I’m finding the average price then traverse the array into reverse sorted order so that i get the number of customer who have more than that average price.

When we get a customer with lower price loop will terminate and multiply the count with the last greater value than the average price.

values = []

t = int(input())

for i in range(t):

n = int(input())

values.append(n)

max_profit = 0

while(len(values)>1):

min_value = min(values)

result = min_value * len(values)

if(result > max_profit):

max_profit = result

values.remove(min_value)

print(max_profit)

I am failing a few test cases can anyone tell me where I am going wrong. please guide me.My code is below.

values = []

t = int(input())

for i in range(t):

n = int(input())

values.append(n)

max_profit = 0

while(len(values)>1):

min_value = min(values)

result = min_value * len(values)

if(result > max_profit):

max_profit = result

values.remove(min_value)

print(max_profit)

1 Like

Maybe it might be TLE.You tried using long long int?

in python there is not long long int just int which can take any number. I have used int only please help me out I am not able to find out where I am going wrong.

It will almost certainly TLE. I hope you know both remove and min are O(n) and you are doing that n times. So your time complexity is O(n^2).

yes it time limit exceeded can you suggest any change in code to reduce TLE please.

Don’t bother removing the element.

Sort the array instead.

bro put for loop at place of while in range of t

it will give you write answer .

1 Like