-
Notifications
You must be signed in to change notification settings - Fork 0
/
best-team-with-no-conflicts.py
32 lines (24 loc) · 1.03 KB
/
best-team-with-no-conflicts.py
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
class Solution:
def bestTeamScore(self, scores: List[int], ages: List[int]) -> int:
# Create a list of indices
indices = list(range(len(scores)))
# #Sort indices based on ages
sorted_indices = sorted(indices, key=lambda i: (ages[i], scores[i]))
# Use sorted indices to rearrange scores and ages
sorted_ages = [ages[i] for i in sorted_indices]
sorted_scores = [scores[i] for i in sorted_indices]
print(sorted_ages)
print(sorted_scores)
result = [0] * len(sorted_scores)
ans = result[0] = sorted_scores[0]
for i in range(len(sorted_scores)):
_max = -inf
for j in range(0, i):
# print(i, j)
if (sorted_scores[j] <= sorted_scores[i]):
_max = max(_max, result[j] + sorted_scores[i])
# print(_max)
result[i] = max(_max, sorted_scores[i])
ans = max(ans, result[i])
print(result)
return ans