Question
complete the code compute_scores to get the following results with the given input Sample Input 5 3 2 1 5 1 2 5 4 3
complete the code compute_scores to get the following results with the given input
Sample Input
5 3
2 1 5
1
2 5 4
3
4
5 3 1
Sample Output
17
10
16
Explanation
There are 5 players in total, and we are asked to report on the scores for players 2, 1 and 5. Observing the history of matches, we see that Player 1 did not defeat anyone, so we know that that player will end with 10 points (everyone gets 10 to start with). Player 2 defeated players 5 and 4, in that order, but we don't know how many points were earned from those players until we look at their win records as well.
Player 5 defeated players 3 and 1. Player 3 defeated no one, so they must have had only their 10 points on entry when they lost to player 5. So, player 5 would have earned 20%*1*10=2 points for defeating player 3. That win would promote player 5 to level 2. So, when they competed against player 1 next, their multiplier was 2. We have already ascertained that player 1 had only 10 points, so player 5 earns 20%*2*10=4 points from defeating player 1. In total, player 5 earned 2+4=6 points, so they would have had a total of 16 points when they lost to player 2.
Now we are ready to calculate player 2's points earned. Defeating player 5 was player 2's first match, so player 2 was still at level 1, and they would have earned 20%*1*16 =3points from it, after which they would have been promoted to level 2. We see that player 4 did not defeat anyone, so we know that they would have had 10 points when they lost to player 2, and therefore player 2 earned 20%*2*10=4 points from that match. In the end, player 2 would have received 10+3+4=17 points.
So, the answers to the queries for players 2, 1 and 5, in that order, were 17, 10 and 16, each of which we output on a separate line.
def compute_scores(history, queries):
# create a function to take a history of performance and a list of queries and compute the scores earned
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started