1. Minimum Health Alex and Charlle are playing an online video game. Initially, there are m players in the first level, and there are next n levels. Each level introduces a new player (along with the players from the previous level). Each player has some strength which determines the difficulty of beating this player. To pass any level, select any available players and beat them. Alex has completed the game and beaten the rank th strongest player at every level. Now it's Charlie's turn to play. Whenever a player is beaten, Charlie's health decreases by the amount of strength of that player. So the initial health of Charlie must be greater than or equal to the sum of the strengths of players that are beaten throughout the game. Charlie does not want to lose to Alex, so Charlie decided to also beat the rank th strongest player at each level. What is the minimum initial health that Charlie needs to start with in order to do this? Example initlal, players =[1,2], new_players =[3,4], rank =2 Charlie needs to beat the 2nd strongest player at each level. For the first level, players have strengths 1 and 2 , so Charlie needs to beat the player with Charlie needs to beat the 2nd strongest player at each level. For the first level, players have strengths 1 and 2, so Charlie needs to beat the player with strength 1. For the second level, strengths are1, 2, and 3, so Charlie defeats strength 2. For the third level, strengths are 1, 2,3, and 4, so Charlie defeats strength 3 . Total health needed =1+2+3=6. Function Description Complete the function getMinimumHealth in the editor below. getMinimumHealth has the following parameter(s): int inital_players[ m] : the strength of initial m players of the game int new_players [n] : the strength of new n players that appear one by one after the first level int rank the rank that p2 needs to beat at every level Returns long: the initial health needed Constraints - 1≤n,m≤105



Answer :

Other Questions