Contest Code:LRNDSA01 Problem Code:ZCO14003 , I am getting wrong answer in it but i had applied correct logic

t=int(input())
l1=[]

for i in range (t):
n=int(input())
l1.append(n)
max_profit = 0
while(len(l1)>1):
min_value=min(l1)
result=min_value*len(l1)
if(result>max_profit):
max_profit=result
l1.remove(min_value)

print(max_profit)

1 Like

No, there is an error in your logic. You are picking up the smallest value from the array but that is not the case everytime.
You have to select a price so that you can get maximum profit.

It is ‘Smart Phone’ question of DSA learning series

you should use

``````l1=list(map(int,input().split()))
``````

Since, input are not in ascending order so your approach is wrong
Now let suppose you have 5 customer and there budgets are as follows
40
3
65
33
21
now if you fixed your selling price to 3, so all the 5 customers can buy and you earn 15 units
and if you fixed your selling price to 21, in this case only 4 person has a budget to buy the smart phone and 1 person having (3 unit) can’t buy the project. So total earning in this case is 81 units
similarly for if you fixed your selling price to 33 only 3 person can able to purchase the phone and your earning is 99 units
such that,
for 40 units only 2 and earning 80 units, and last
for 65 units only 1 and earning 65 units.

and from the above we can conclude 99 units is max and bingo
Hope this help.

2 Likes

I think it should not be used here since the array elements are not in same line

Refer to this post Editorial for Problems of Codechef-DSA-Learning-Series: 1-Complexity Analysis + Basics Warm Up if you are facing the problem related to any problem in the Code-Chef DSA Learning Contest.

I have the correct answer but still got “WA”. :’)