Untitled
unknown
plain_text
2 years ago
2.5 kB
3
Indexable
Never
from collections import defaultdict n = int(input()) disciplines = {} for i in range(n): name, partic = input().split(',') disciplines[name] = int(partic) disciplines[name] = { 'max': int(partic), 'players': defaultdict(dict), 'count': 0, 'maxScore': None, 'minScore': None, } def addPlayer(disc, name, score, fine): disc['players'][score].update({fine : name}) disc['count'] += 1 if disc['count'] > 1: disc['maxScore'] = max(disc['maxScore'], score) disc['minScore'] = min(disc['minScore'], score) else: disc['maxScore'] = score disc['minScore'] = score m = int(input()) players = {} for i in range(m): name, discName, score, fine = input().split(',') score = int(score) fine = int(fine) dis = disciplines[discName] players = dis['players'] if dis['count'] < dis['max']: addPlayer(dis, name, score, fine) else: if dis['minScore'] < score: weak = players[dis['minScore']] if len(weak) == 1: dis['count'] -= 1 del players[dis['minScore']] scores = players.keys() cMin = scores[0] cMax = scores[0] for s in scores: if s < cMin: cMin = s if s > cMax: cMax = s dis['minScore'] = cMin dis['maxScore'] = cMax addPlayer(dis, name, score, fine) else: fines = players[dis['minScore']].keys() cMax = fines[0] for f in fines: if f > cMax: cMax = f exfine = cMax dis['count'] -= 1 del players[dis['minScore']][exfine] addPlayer(dis, name, score, fine) elif dis['minScore'] == score: fines = players[dis['minScore']].keys() cMax = fines[0] for f in fines: if f > cMax: cMax = f exfine = cMax if exfine > fine: dis['count'] -= 1 del players[dis['minScore']][exfine] addPlayer(dis, name, score, fine) disciplines[discName] = dis winners = [] for d in disciplines.values(): for s in d['players'].values(): for p in s.values(): winners.append(p) winners.sort() for w in winners: print(w)