Three friends gathered to play a few games of chess together.In every game, two of them play against each other. The winner gets 22 points while the loser gets 00, and in case of a draw, both players get 11 point each. Note that the same pair of players could have played any non-negative number of times (possibly zero). It is also possible that no games were played at all.You've been told that their scores after all the games were played were p1𝑝1, p2𝑝2 and p3𝑝3. Additionally, it is guaranteed that p1≤p2≤p3𝑝1≤𝑝2≤𝑝3 holds.Find the maximum number of draws that could have happened and print it. If there isn't any way to obtain p1𝑝1, p2𝑝2 and p3𝑝3 as a result of a non-negative number of games between the three players, print −1−1 instead.InputEach test contains multiple test cases. The first line contains the number of test cases t𝑡 (1≤t≤5001≤𝑡≤500). The description of the test cases follows.The first line of each test case contains three integers p1𝑝1, p2𝑝2 and p3𝑝3 (0≤p1≤p2≤p3≤300≤𝑝1≤𝑝2≤𝑝3≤30) — the scores of the three players, sorted non-decreasingly.OutputFor each testcase, print one number — the maximum possible number of draws that could've happened, or −1−1 if the scores aren't consistent with any valid set of games and results.ExampleinputCopy70 0 00 1 11 1 11 1 23 3 33 4 51 1 10outputCopy01-12-162NoteIn the first example, no games were played at all, so no draws could occur either.For the second example, exactly one game occurred between the second and the third player and it ended in draw, so the answer is 11.It's easy to see that there's no set of games achieving the scores in third example, so the answer for it is −1−1.
Question
Three friends gathered to play a few games of chess together.In every game, two of them play against each other. The winner gets 22 points while the loser gets 00, and in case of a draw, both players get 11 point each. Note that the same pair of players could have played any non-negative number of times (possibly zero). It is also possible that no games were played at all.You've been told that their scores after all the games were played were p1𝑝1, p2𝑝2 and p3𝑝3. Additionally, it is guaranteed that p1≤p2≤p3𝑝1≤𝑝2≤𝑝3 holds.Find the maximum number of draws that could have happened and print it. If there isn't any way to obtain p1𝑝1, p2𝑝2 and p3𝑝3 as a result of a non-negative number of games between the three players, print −1−1 instead.InputEach test contains multiple test cases. The first line contains the number of test cases t𝑡 (1≤t≤5001≤𝑡≤500). The description of the test cases follows.The first line of each test case contains three integers p1𝑝1, p2𝑝2 and p3𝑝3 (0≤p1≤p2≤p3≤300≤𝑝1≤𝑝2≤𝑝3≤30) — the scores of the three players, sorted non-decreasingly.OutputFor each testcase, print one number — the maximum possible number of draws that could've happened, or −1−1 if the scores aren't consistent with any valid set of games and results.ExampleinputCopy70 0 00 1 11 1 11 1 23 3 33 4 51 1 10outputCopy01-12-162NoteIn the first example, no games were played at all, so no draws could occur either.For the second example, exactly one game occurred between the second and the third player and it ended in draw, so the answer is 11.It's easy to see that there's no set of games achieving the scores in third example, so the answer for it is −1−1.
Solution
The problem is asking to find the maximum number of draws that could have happened in a series of chess games between three friends. The scores of the three players are given, and the task is to determine if these scores could have been achieved through a series of games, and if so,
Similar Questions
A total of 11 teams participated in a hockey tournament in which every team played exactly one match with every other team. In any match, a team gets four points for a win, three points for a draw and two points for a loss. The total score of no two teams was the same at the end of the tournament. If the number of points of the team with the highest total score is 35, then which of the following could be the number of points of the team with the least total score?
The King wants to marry off his daughter, and he wants her husband to have the greatest innate luckiness possible. To find such a person he decided to hold a heads-or-tails tournament.If person A𝐴 with luckiness x𝑥 and person B𝐵 with luckiness y𝑦 play heads-or-tails against each other, person A𝐴 wins with probability x/(x+y)𝑥/(𝑥+𝑦).The tournament has several rounds. Each round some participants are split into pairs. Each pair plays against each other, and the loser leaves the tournament.The participants are numbered from 11 to n𝑛. During the first round, a number k𝑘 (1≤k≤n1≤𝑘≤𝑛) is selected such that n−k/2𝑛−𝑘/2 is a power of 22 (such k𝑘 always exists and is unique). Only participants numbered from 11 to k𝑘 take part in the first round. It ensures that in all other rounds the number of participants is the power of 22.During other rounds, all the participants who still have not left the tournament take part. If during some round, participants numbered p1<…<p2m𝑝1<…<𝑝2𝑚 take part, then they are split into pairs in the following manner: participant p2i−1𝑝2𝑖−1 plays against participant p2i𝑝2𝑖 for each i𝑖 from 11 to m𝑚.The rounds are held until only one participant is left. He is declared the winner of the tournament and he will marry the King's daughter. The princess can't wait to find out who is her future husband. She asked every participant to tell her his luckiness. Assuming they did not lie, she wants to know the probability of each participant winning the tournament. As you are the best friend of the princess, she asks you to help her.InputThe first line of the input contains the number of participants, n𝑛 (2≤n≤3⋅1052≤𝑛≤3⋅105). The second line of the input contains n𝑛 integer numbers, a1,…,an𝑎1,…,𝑎𝑛 (1≤ai≤1091≤𝑎𝑖≤109). The luckiness of the i𝑖-th participant equals to ai𝑎𝑖.OutputPrint n𝑛 numbers pi𝑝𝑖. The i𝑖-th number should be the probability of the i𝑖-th participant winning the tournament. The absolute error of your answer must not exceed 10−910−9.ExampleinputCopy51 4 1 1 4outputCopy0.026 0.3584 0.0676 0.0616 0.4864NoteHere is an example of a tournament bracket, showing the winning probability in each pair.
Alice and Bob came up with a rather strange game. They have an array of integers a1,a2,…,an𝑎1,𝑎2,…,𝑎𝑛. Alice chooses a certain integer k𝑘 and tells it to Bob, then the following happens:Bob chooses two integers i𝑖 and j𝑗 (1≤i<j≤n1≤𝑖<𝑗≤𝑛), and then finds the maximum among the integers ai,ai+1,…,aj𝑎𝑖,𝑎𝑖+1,…,𝑎𝑗;If the obtained maximum is strictly greater than k𝑘, Alice wins, otherwise Bob wins.Help Alice find the maximum k𝑘 at which she is guaranteed to win.InputEach test consists of multiple test cases. The first line contains a single integer t𝑡 (1≤t≤1041≤𝑡≤104) — the number of test cases. The description of the test cases follows.The first line of each test case contains a single integer n𝑛 (2≤n≤5⋅1042≤𝑛≤5⋅104) — the number of elements in the array.The second line of each test case contains n𝑛 integers a1,a2,…,an𝑎1,𝑎2,…,𝑎𝑛 (1≤ai≤1091≤𝑎𝑖≤109) — the elements of the array.It is guaranteed that the sum of n𝑛 over all test cases does not exceed 5⋅1045⋅104.OutputFor each test case, output one integer — the maximum integer k𝑘 at which Alice is guaranteed to win.ExampleinputCopy642 4 1 751 2 3 4 521 1337 8 16510 10 10 10 9103 12 9 5 2 3 2 9 8 2outputCopy3101592NoteIn the first test case, all possible subsegments that Bob can choose look as follows: [2,4],[2,4,1],[2,4,1,7],[4,1],[4,1,7],[1,7][2,4],[2,4,1],[2,4,1,7],[4,1],[4,1,7],[1,7]. The maximums on the subsegments are respectively equal to 4,4,7,4,7,74,4,7,4,7,7. It can be shown that 33 is the largest integer such that any of the maximums will be strictly greater than it.In the third test case, the only segment that Bob can choose is [1,1][1,1]. So the answer is 00.
There are 2 teams, each having N players. There will be N rounds played between the 2 teams. In every round, a player from team A plays against a player from team B. The more powerful player wins the game. Given the strength of the players of both teams, you have to find the maximum number of rounds team A can win. Note that a player cannot play more than 1 round.Input FormatThe first line of input contains T - the number of test cases. It's followed by 3T lines. The first line contains the N - the size of the team. The next 2 lines contain N numbers each - the strength of the players of team A and team B respectively.Output FormatFor each test case, print the maximum number of rounds team A can win, separated by a new line.Constraints1 <= T <= 5001 <= N <= 100000 <= A[i], B[i] <= 10000ExampleInput341 5 7 4 3 8 2 10 22 3 10 5 33 7 10 5 20 15 Output201ExplanationTest-Case 1Player with strength 5 in team A can defeat player with strength 3 in team B.Player with strength 7 in team A can defeat player with strength 2 in team B.Test-Case 2No Player in team A can defeat any player in team B.Test-Case 3Player with strength 7 in team A can defeat player with strength 5 in team B.
There are 2 teams, each having N players. There will be N rounds played between the 2 teams. In every round, a player from team A plays against a player from team B. The more powerful player wins the game. Given the strength of the players of both the teams, you have to find the maximum number of rounds team A can win. Note that a player cannot play more than 1 round.Input FormatFirst line of input contains T - number of test cases. Its followed by 3T lines. The first line contains N - size of the team. The next 2 lines contains N numbers each - strength of the players of team A and team B respectively.Constraints1 <= T <= 5001 <= N <= 100000 <= A[i], B[i] <= 10000Output FormatFor each test case, print the maximum number of rounds team A can win, separated by newline.Sample Input 0341 5 7 4 3 8 2 10 22 3 10 5 33 7 10 5 20 15 Sample Output 0201Explanation 0Test Case 1Player with strength 5 in team A can defeat player with strength 3 in team B.Player with strength 7 in team A can defeat player with strength 2 in team B.Test Case 2No Player in team A can defeat any player in team B.Test Case 3Player with strength 7 in team A can defeat player with strength 5 in team B.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.