-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclimbing_the_leaderboard.py
More file actions
executable file
·47 lines (36 loc) · 1.2 KB
/
climbing_the_leaderboard.py
File metadata and controls
executable file
·47 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
from typing import IO
def climbingLeaderboard(ranked: list[int], player: list[int]) -> list[int]:
ranks = []
current_rank = 1
last_ranked_score = -1
for ranked_score in ranked:
while len(player) > 0 and player[-1] >= ranked_score:
ranks.insert(0, current_rank)
player.pop()
if ranked_score != last_ranked_score:
current_rank += 1
last_ranked_score = ranked_score
while len(player) > 0:
ranks.insert(0, current_rank)
player.pop()
return ranks
def main(fptr: IO) -> None:
ranked_count = int(input().strip())
ranked = list(map(int, input().rstrip().split()))
assert len(ranked) == ranked_count
player_count = int(input().strip())
player = list(map(int, input().rstrip().split()))
assert len(player) == player_count
result = climbingLeaderboard(ranked, player)
fptr.write("\n".join(map(str, result)) + "\n")
if __name__ == "__main__":
if path := os.getenv("OUTPUT_PATH"):
with Path(path).open("wt", encoding="utf-8") as fptr:
main(fptr)
fptr.close()
else:
main(sys.stdout)