Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- import math
- def get_party():
- *party_name, votes = input().split()
- return " ".join(party_name), int(votes)
- def get_total_vote(parties):
- return sum(party[1] for party in parties)
- def first_round(parties, first_private):
- return {party: int(votes // first_private) for party, votes in parties}
- def second_round(parties, first_private):
- mods = [(math.modf(votes / first_private)[0], votes, party) for party, votes in parties]
- mods.sort()
- return [party for *_, party in reversed(mods)]
- parties = []
- places = defaultdict(int)
- while True:
- try: party = get_party()
- except EOFError: break
- parties.append(party)
- total_vote = get_total_vote(parties)
- first_private = total_vote / 450
- places.update(first_round(parties, first_private))
- add_places = second_round(parties, first_private)
- need_places = 450 - sum(places.values())
- for party in add_places:
- if need_places == 0: break
- places[party] += 1
- need_places -= 1
- for party, _ in parties:
- print(party, places[party])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement