hardDynamic Programming 1DPure DSA~40 min
Highest-Scoring Team Without Age-Score Conflicts
Build a team to maximize total score. A conflict arises if a younger member has a strictly higher score than an older one, so the chosen members must be conflict-free.
Problem
Given arrays scores and ages of the same length, choose a subset of players maximizing the sum of scores such that no chosen player is both younger and strictly higher-scoring than another chosen player. Return the maximum total score.
Input
Two arrays scores and ages of equal length n.
Output
An integer: the maximum conflict-free team score.
Constraints
- 1 <= n <= 1000
- 1 <= scores[i] <= 10^6, 1 <= ages[i] <= 1000
- Ties in age or score do not cause conflicts.
Examples
Example 1
Input
scores = [1,3,5,10,15], ages = [1,2,3,4,5]
Output
34
All players are conflict-free; the whole team sums to 34.
Example 2
Input
scores = [4,5,6,5], ages = [2,1,2,1]
Output
16
Choose the two age-1 players (5+5) and the age-2 player with score 6: 16.