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
count = int(input())
prices = []
for _ in range(count):
prices.append(int(input()))
ans = sum(sorted(prices, reverse=True)[0:2])
print(ans)
Comments
Leave a comment