i has a rating ratings[i] and an age ages[i]. The strength of a squad is the sum of the ratings of everyone in it.
The squad must be free of grudges: a grudge arises when one player is strictly younger than another yet has a strictly higher rating. Players of the same age never hold grudges.
Return the greatest strength a squad can have. A squad of a single player is allowed.ratings=[6, 4, 8, 2], ages=[30, 25, 22, 40] → 10
The 22-year-old rated 8 outrates every older player, so a roster with him holds just him: 8. Without him, take the players aged 25 and 30: 4 + 6 = 10. The 40-year-old rated 2 cannot join them, since younger players outrate him. The answer is 10.
ratings=[7, 3, 5], ages=[20, 20, 20] → 15
Everyone is the same age, so there are no conflicts: take all of them, 7 + 3 + 5 = 15.
ratings=[9], ages=[50] → 9
len(ratings) = len(ages) ≤ 1000ratings[i] ≤ 10⁶ages[i] ≤ 1000ratings=[6, 4, 8, 2], ages=[30, 25, 22, 40]
10
Run checks the first 3 tests in your browser. Submit checks all 138 tests on the server, hidden ones included.