310728: CF1877A. Goals of Victory

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. Goals of Victorytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $n$ teams in a football tournament. Each pair of teams match up once. After every match, Pak Chanek receives two integers as the result of the match, the number of goals the two teams score during the match. The efficiency of a team is equal to the total number of goals the team scores in each of its matches minus the total number of goals scored by the opponent in each of its matches.

After the tournament ends, Pak Dengklek counts the efficiency of every team. Turns out that he forgot about the efficiency of one of the teams. Given the efficiency of $n-1$ teams $a_1,a_2,a_3,\ldots,a_{n-1}$. What is the efficiency of the missing team? It can be shown that the efficiency of the missing team can be uniquely determined.

Input

Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 500$) — the number of test cases. The following lines contain the description of each test case.

The first line contains a single integer $n$ ($2 \leq n \leq 100$) — the number of teams.

The second line contains $n-1$ integers $a_1,a_2,a_3,\ldots,a_{n-1}$ ($-100\leq a_i\leq100$) — the efficiency of $n-1$ teams.

Output

For each test case, output a line containing an integer representing the efficiency of the missing team.

ExampleInput
2
4
3 -4 5
11
-30 12 -57 7 0 -81 -68 41 -89 0
Output
-4
265
Note

In the first test case, below is a possible tournament result:

  • Team $1$ vs. Team $2$: $1-2$
  • Team $1$ vs. Team $3$: $3-0$
  • Team $1$ vs. Team $4$: $3-2$
  • Team $2$ vs. Team $3$: $1-4$
  • Team $2$ vs. Team $4$: $1-3$
  • Team $3$ vs. Team $4$: $5-0$

The efficiency of each team is:

  1. Team $1$: $(1+3+3)-(2+0+2)=7-4=3$
  2. Team $2$: $(2+1+1)-(1+4+3)=4-8=-4$
  3. Team $3$: $(0+4+5)-(3+1+0)=9-4=5$
  4. Team $4$: $(2+3+0)-(3+1+5)=5-9=-4$

Therefore, the efficiency of the missing team (team $4$) is $-4$.

It can be shown that any possible tournament of $4$ teams that has the efficiency of $3$ teams be $3$, $-4$, and $5$ will always have the efficiency of the $4$-th team be $-4$.

Output

题目大意:
在一场足球锦标赛中,共有 $ n $ 支队伍参加。每两支队伍之间都会进行一场比赛。每次比赛后,Pak Chanek 会收到两个整数作为比赛结果,即两支队伍在比赛中进球的数量。一支队伍的效率定义为该队在所有比赛中进球总数减去该队在所有比赛中对手进球的总数。

锦标赛结束后,Pak Dengklek 会计算每支队伍的效率。但他忘记了一支队伍的效率。已知 $ n-1 $ 支队伍的效率 $ a_1, a_2, a_3, \ldots, a_{n-1} $,需要求出缺失队伍的效率。可以证明,缺失队伍的效率是可以唯一确定的。

输入输出数据格式:
输入:
- 第一行包含一个整数 $ t $($ 1 \leq t \leq 500 $),表示测试用例的数量。
- 每个测试用例的描述如下:
- 第一行包含一个整数 $ n $($ 2 \leq n \leq 100 $),表示队伍的数量。
- 第二行包含 $ n-1 $ 个整数 $ a_1, a_2, a_3, \ldots, a_{n-1} $($ -100 \leq a_i \leq 100 $),表示 $ n-1 $ 支队伍的效率。

输出:
- 对于每个测试用例,输出一行包含一个整数,表示缺失队伍的效率。

示例:
输入:
```
2
4
3 -4 5
11
-30 12 -57 7 0 -81 -68 41 -89 0
```
输出:
```
-4
265
```

注意:
在第一个测试用例中,可能的比赛结果如下:
- 队伍 1 vs. 队伍 2: 1-2
- 队伍 1 vs. 队伍 3: 3-0
- 队伍 1 vs. 队伍 4: 3-2
- 队伍 2 vs. 队伍 3: 1-4
- 队伍 2 vs. 队伍 4: 1-3
- 队伍 3 vs. 队伍 4: 5-0

每支队伍的效率如下:
- 队伍 1: $ (1+3+3)-(2+0+2)=7-4=3 $
- 队伍 2: $ (2+1+1)-(1+4+3)=4-8=-4 $
- 队伍 3: $ (0+4+5)-(3+1+0)=9-4=5 $
- 队伍 4: $ (2+3+0)-(3+1+5)=5-9=-4 $

因此,缺失队伍(队伍 4)的效率是 -4。可以证明,任何可能的 4 支队伍的锦标赛,如果其中 3 支队伍的效率是 3, -4, 5,那么第 4 支队伍的效率总是 -4。题目大意: 在一场足球锦标赛中,共有 $ n $ 支队伍参加。每两支队伍之间都会进行一场比赛。每次比赛后,Pak Chanek 会收到两个整数作为比赛结果,即两支队伍在比赛中进球的数量。一支队伍的效率定义为该队在所有比赛中进球总数减去该队在所有比赛中对手进球的总数。 锦标赛结束后,Pak Dengklek 会计算每支队伍的效率。但他忘记了一支队伍的效率。已知 $ n-1 $ 支队伍的效率 $ a_1, a_2, a_3, \ldots, a_{n-1} $,需要求出缺失队伍的效率。可以证明,缺失队伍的效率是可以唯一确定的。 输入输出数据格式: 输入: - 第一行包含一个整数 $ t $($ 1 \leq t \leq 500 $),表示测试用例的数量。 - 每个测试用例的描述如下: - 第一行包含一个整数 $ n $($ 2 \leq n \leq 100 $),表示队伍的数量。 - 第二行包含 $ n-1 $ 个整数 $ a_1, a_2, a_3, \ldots, a_{n-1} $($ -100 \leq a_i \leq 100 $),表示 $ n-1 $ 支队伍的效率。 输出: - 对于每个测试用例,输出一行包含一个整数,表示缺失队伍的效率。 示例: 输入: ``` 2 4 3 -4 5 11 -30 12 -57 7 0 -81 -68 41 -89 0 ``` 输出: ``` -4 265 ``` 注意: 在第一个测试用例中,可能的比赛结果如下: - 队伍 1 vs. 队伍 2: 1-2 - 队伍 1 vs. 队伍 3: 3-0 - 队伍 1 vs. 队伍 4: 3-2 - 队伍 2 vs. 队伍 3: 1-4 - 队伍 2 vs. 队伍 4: 1-3 - 队伍 3 vs. 队伍 4: 5-0 每支队伍的效率如下: - 队伍 1: $ (1+3+3)-(2+0+2)=7-4=3 $ - 队伍 2: $ (2+1+1)-(1+4+3)=4-8=-4 $ - 队伍 3: $ (0+4+5)-(3+1+0)=9-4=5 $ - 队伍 4: $ (2+3+0)-(3+1+5)=5-9=-4 $ 因此,缺失队伍(队伍 4)的效率是 -4。可以证明,任何可能的 4 支队伍的锦标赛,如果其中 3 支队伍的效率是 3, -4, 5,那么第 4 支队伍的效率总是 -4。

加入题单

上一题 下一题 算法标签: