Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contests = {} # contest : password, user, max(points)
- users = {} # user : contest, points
- while True:
- command = input().split(":")
- if command[0] == "end of contests":
- break
- contest = command[0]
- password = command[1]
- if contest not in contests:
- contests[contest] = {"pass": password}
- while True:
- command = input().split("=>")
- if command[0] == "end of submissions":
- break
- contest = command[0]
- password = command[1]
- user = command[2]
- points = int(command[3])
- if contest not in contests or contests[contest]["pass"] != password:
- continue
- if user not in contests[contest]:
- contests[contest] = {"pass": password, user: points}
- elif user in contests[contest] and points > contests[contest][user]:
- contests[contest][user] = points
- if user not in users:
- users[user] = {"sum": points, contest: points}
- elif user in users and contest not in users[user]:
- users[user][contest] = points
- users[user]["sum"] += points
- elif user in users and contest in users[user] and points > users[user][contest]:
- users[user]["sum"] -= users[user][contest]
- users[user][contest] = points
- users[user]["sum"] += points
- best_user = max(users, key=lambda x: users[user]["sum"])
- best_sum = users[best_user]["sum"]
- print(f"Best candidate is {best_user} with total {best_sum} points.\n"
- f"Ranking:")
- for user in sorted(users):
- users[user].pop("sum")
- print(user)
- users = {key: dict(sorted(val.items(), key=lambda ele: ele[1], reverse=True)) for key, val in users.items()}
- for contest in users[user]:
- print(f"# {contest} -> {users[user][contest]}")
Advertisement
Add Comment
Please, Sign In to add comment