Computers and Technology

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 - 1n,m105
2. Busy intersection There is a busy intersection between two one-way streets: Main Street and 1st Avenue. Cars passing through the intersection can only pass through one at a time. When multiple cars arrive at the intersection at the same time, two queues can build up - one for each street. Cars are added to the queue in the order at which they arrive. Unfortunately, there is no traffic light to help control traffic when multiple cars arrive at the same time. So, the local residents have devised their own system for determining which car has priority to pass through the intersection: - If in the previous second, no car passed through the intersection, then the first car in the queue for 1 st Avenue goes first. - If in the previous second, a car passed through the intersection on 1st Avenue, then the first car in the queue for1stAvenue goes first. - If in the previous second, a car passed through the intersection on Main Street, then the first car in the queue for Main Street goest first. Passing through the intersection takes 1 second. For each car, find the time when they will pass through the intersection. Function Description Complete the function getResult in the editor below. getResult has the following parameters: int arrival [n]: an array ofnintegers where the value at indexiis the time in seconds when thei th car arrives at the intersection. If arrival[i]=arrival[j] andi, then cariarrives before carj. int street[n]: an array ofnintegers where the value at indexiis the street on which thet th car is traveling: Street and 1 for 1 st Avenue. Returns:int[n]:an array ofnintegers where the value at indexiis the time when thei th car will pass through the intersection Constraints -1n10 5-0arrival[i]10 9for0in1- arrival[i]arrival[i+1]for0in2-0sstreet[i]1for0in1