Smart Phone

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

this is the way you can follow!

coz they will be paying 30 and not 30 or 54
you need to get price that all the customers will pay
revenue = price * customers that buy them
customers only buy them if price is lower or equal to their expectations

i have done this according to your explanation but still its showing partially correct.

code given below

num = int(input())
budget = []
while num>0:
b = int(input())
budget.append(b)
num-=1

revenue = [];
for price in budget:
r=0
for i in budget:
if i>=price:
r += price
revenue.appendÂŽ

revenue.sort()

print(revenue[-1])

n = int(input())

inp = []

for i in range(n):

inp.append(int(input()))

inp.sort()

def smart(n , inp):

minm = []

for j in range(n):

    if minm == None:
        minm = inp[j]*(n-j)
    else:
        minm.append(inp[j]*(n-j))
return max(minm)

print(smart(n, inp))

Thank You sir for sharing explaination for this problem. It’s very helpful

Hello Everyone, I have implemented solution for Smart Phone Problem and this solution gives correct output also but after submitting this solution my submission


status showing wrong . Anyone can help me what changes required for successful submission. Below I have mentioned my solution

Please either paste your (formatted!) code or (better!) link to your submission - no one wants to squint at a PNG :slight_smile:

Solution: 53048725 | CodeChef

1 Like

Thanks! That’s not “wrong” (WA), that’s “Time Limit Exceeded” (TLE) i.e. your solution is too slow.

Thank you sir, so i need to change whole solution or can i run this solution with any changes?

Can we do this problem without sorting like using DP? In O(n)?