Editorial for T-Shirts


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

We make the observation that every time we have a free T-shirt deal, we should redeem it for the most expensive T-shirt – that is, large if there are any, otherwise medium if there are any, otherwise small. An easy way to implement this is to put all T-shirts in sorted order inside a double-ended list and keep popping from both sides.

s,m,l = map(int,raw_input().split())
a,b,c = map(float,raw_input().split())
total = 0.0
costs = []
for i in range(s):
    costs.append(a)
for i in range(m):
    costs.append(b)
for i in range(l):
    costs.append(c)
count = 0
while costs:
    total += costs.pop(0)
    count += 1
    if count % 3 ==0 and costs:
        costs.pop(-1)
print format(total,".2f")

Comments

There are no comments at the moment.