Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from operator import itemgetter
- count = int(input())
- rows = [input().strip() for i in range(count)]
- # rows = [
- # "Космопит (300 г): Крем-суп грибной - 400, Борщ - 410",
- # "АстроЕда (150 г): Борщ - 210, Крем-суп грибной - 220"
- # ]
- # rows = [
- # "АстроЕда (150 г): Борщ - 200, Крем-суп грибной - 185",
- # "Космопит (300 г): Торт Москва - 410, Борщ - 450"
- # ]
- items = []
- global_eats = {}
- minimums = {}
- for row in rows:
- brandAndWeight, eats = row.split(': ')
- brand, weight = brandAndWeight.split(' (')
- weight = weight.replace(' г)', '')
- eats = eats.split(', ')
- for eat in eats:
- name, price = eat.split(' - ')
- cost = math.ceil(300 / int(weight)) * int(price)
- items.append({
- 'brand': brand,
- 'name': name,
- 'price': price,
- 'cost': cost,
- 'weight': math.ceil(300 / int(weight)) * int(weight)
- })
- if name in global_eats:
- global_eats[name] += cost
- else:
- global_eats[name] = cost
- if name in minimums:
- if int(minimums[name]) > int(price):
- minimums[name] = price
- else:
- minimums[name] = price
- global_eats = sorted(global_eats.items(), key = lambda i: i[1])
- minimums = sorted(minimums.items(), key = lambda i: i[1])
- minimums.reverse()
- # print(minimums[0][1])
- items = sorted(items, key=lambda i: i['cost'])
- items.reverse()
- brandname = ''
- # eatname = global_eats[0][0]
- eatname = minimums[0][0]
- print(eatname + ':')
- for item in items:
- if (eatname == item['name']):
- print(' - '.join([item['brand'], str(item['cost'])]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement