#1626
Best Team With No Conflicts
specialist · 855 · lc medium +31 · verified · 50.6% accepted · 3,047 likes · top 39%
Description
You are managing a basketball team for a tournament. A conflict occurs when a younger player has a strictly higher score than an older one (same-age players never conflict). Given scores and ages, choose any subset of players with no conflicts that maximizes the total score. Return that maximum score.
Example 1:
Input: scores = [1,3,5,10,15], ages = [1,2,3,4,5]
Output: 34
Explanation: You can choose all the players.
Example 2:
Input: scores = [4,5,6,5], ages = [2,1,2,1]
Output: 16
Explanation: It is best to choose the last 3 players. Notice that you are allowed to choose multiple people of the same age.
Example 3:
Input: scores = [1,2,3,5], ages = [8,9,10,1]
Output: 6
Explanation: It is best to choose the first 3 players.
Code
1
2
3