-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrank.py
More file actions
66 lines (47 loc) · 1.23 KB
/
rank.py
File metadata and controls
66 lines (47 loc) · 1.23 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the climbingLeaderboard function below.
def climbingLeaderboard(scores, alice):
dict={}
lis=[]
res=[]
for i in range(len(scores)):
try:
d=dict[scores[i]]
except:
lis.append(scores[i])
dict[scores[i]]=1
n=len(lis)
for i in range(len(alice)):
start=0
end=n-1
if alice[i]<lis[n-1]:
res.append(n+1)
continue
while(start<end):
mid=int((start+end)/2)
if alice[i]>lis[mid]:
end=mid-1
elif alice[i]<lis[mid]:
start=mid+1
else:
res.append(mid+1)
print(mid+1)
break
else:
if start==end:
res.append(start+1)
else:
res.append(end+3)
return res
if __name__ == '__main__':
scores_count = int(input())
scores = list(map(int, input().rstrip().split()))
alice_count = int(input())
alice = list(map(int, input().rstrip().split()))
result = climbingLeaderboard(scores, alice)
print(result)