Skip to content

Latest commit

 

History

History
24 lines (22 loc) · 669 Bytes

1626.md

File metadata and controls

24 lines (22 loc) · 669 Bytes

1626. Best Team With No Conflicts

Solution 1 (time O(nlog(n)), space O(n))

# Dynamic programming
class Solution(object):
    def bestTeamScore(self, scores, ages):
        """
        :type scores: List[int]
        :type ages: List[int]
        :rtype: int
        """
        people = sorted(zip(scores, ages))
        dp = [0 for _ in range(len(scores))]
        ans = 0
        for i in range(len(scores)):
            for j in range(i):
                if people[i][1] >= people[j][1]:
                    dp[i] = max(dp[i], dp[j])
            dp[i] += people[i][0]
            ans = max(ans, dp[i])
        return ans