Answer to Question #336258 in Python for sandhya

Question #336258

Discount sale:

it is a summer discount sale in mumbai and all the local shops have put up various offers Arjun selected N items to buy while standing in the building queue,he noticed the offer "buy two !" get two FREE!".this means that for every two items he buys they give him two items for free however ,items can be of varying prices they always charge for two most costly items and give the other two as free.Arjun is confused with grouping his items to reduce the total price he has to pay your task is to find the minimum price arjun has to pay to buy all the N items

input:the 1st line contains a single integer N

the 2nd line has N space-separated integers representing the cost of items

input:

4

1 1 2 2

o/p:4

i/p:

2

10 200

output:

210


1
Expert's answer
2022-05-03T14:19:21-0400
count = int(input())
prices = []

for _ in range(count):
    prices.append(int(input()))

ans = sum(sorted(prices, reverse=True)[0:2])
print(ans)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS