Codey and Team Selection
https://www.hackerrank.com/contests/codenection-2023-preliminary-round-closed-category/challenges/cn-c6
Question
Codey is a coach, and it is assembling a team for a competitive sports league. It is going to select n
players for the team. Each player possesses a skill point represented by . The player selection process consists of n
steps, and in each step:
Let
b
to be the sorted array of skill points for unselected players. Choose an integerj
, where , and k is the current total of unselected players, that player joins the team and gains an additional skill point, . In other words, the total team skill increases by .
Codey wants to strategically select players to maximize the overall team skill for the upcoming sports league, while following the constraints of the selection process. Can you help Codey to achieve this?
Input Format
The first line contains a single integer n
, which represents the number of players.
The second line contains n
integers , each representing the skill points of the -th player.
The third line contains n
integers , each representing the additional skill points gained for selecting the -th player in the array b
.
Constraints
Output Format
Output an integer representing the maximum total team skill.
Sample Inputs:
Input
3
1 2 3
3 3 1
Output
15
Explanation
We can select the players as such:
The current team skill is and
b = [1, 2, 3]
. We choosej = 1
and the team skill increase by .The current team skill is and
b = [2, 3]
. We choosej = 2
and the team skill increase by .The current team skill is and
b = [2]
. We choosej = 1
and the team skill increase by .All players are selected, selection ended. The total team skill is .
Last updated