FunctionRacerProblemsRace

Fast and Careful Team

HardSorting and searchingPython, JavaScript, TypeScript, Java, C++

Worker i has a speed speeds[i] and a care score cares[i]. Choose a team of at least one and at most k workers. The score of a team is the sum of its speeds times the smallest care score on the team.

Return the best score a team can have.

Example 1

speeds [4,9,3]
cares [6,2,5]
k 2
returns 35

Workers 0 and 2 have speeds 4 + 3 = 7 and the smaller care score is 5: 35. The fast worker 1 would drag the care score down to 2.

Example 2

speeds [10,1]
cares [1,10]
k 2
returns 11

Both together: speeds 10 + 1 = 11, times the smaller care score 1. Either worker alone scores 10.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems