CF1552B Running for Gold

题目描述

### 【题目大意】 奥运比赛刚刚开始,Federico 便十分渴望观看比赛。 有 $n$ 个选手参加了马拉松比赛,从 $1$ 到 $n$ 依次编号。她们**都**参加了 $5$ 项比赛,比赛从 $1$ 到 $5$ 编号。 现在有一个二维的数组 $r_{i,j}(1 \leq i \leq n,1 \leq j \leq 5)$,表示选手 $i$ 在比赛 $j$ 中排名第 $r_{i,j}$ 名。 Federico 认为选手 $u$ 优于选手 $v$,当且仅当,$u$ 在**至少** $3$ 个项目中战胜了 $v$(即排名在 $v$ 前)。 Federico 认为选手 $x$ 能够获得金牌当且仅当 $x$ 可以战胜其它**所有**选手。 给定 $r_{i,j}$,求是否有一名选手可以获得金牌。

输入格式

**多组数据**。 第一行 $T(1 \leq T \leq 1000)$,表示数据组数。 每组数据第一行 $n(1 \leq n \leq 50000)$,表示比赛数目。 接下来 $n$ 行,每行 $5$ 个数,表示 $r_{i, 1 \cdots 5}$。保证对于任意 $1 \leq j \leq 5$,$r_{1 \cdots n,j}$ 互不相同。 保证 $\sum n \leq 50000$。

输出格式

每组数据输出一行,表示金牌得主。 **如果没有人能够获得金牌,则输出 `-1`**。 **如果有不止一个人可以获得金牌,输出任意即可**。 -------------------- Translated by @HPXXZYY.

说明/提示

Explanation of the first test case: There is only one athlete, therefore he is superior to everyone else (since there is no one else), and thus he is likely to get the gold medal. Explanation of the second test case: There are $ n=3 $ athletes. - Athlete $ 1 $ is superior to athlete $ 2 $ . Indeed athlete $ 1 $ ranks better than athlete $ 2 $ in the marathons $ 1 $ , $ 2 $ and $ 3 $ . - Athlete $ 2 $ is superior to athlete $ 3 $ . Indeed athlete $ 2 $ ranks better than athlete $ 3 $ in the marathons $ 1 $ , $ 2 $ , $ 4 $ and $ 5 $ . - Athlete $ 3 $ is superior to athlete $ 1 $ . Indeed athlete $ 3 $ ranks better than athlete $ 1 $ in the marathons $ 3 $ , $ 4 $ and $ 5 $ . Explanation of the third test case: There are $ n=3 $ athletes. - Athlete $ 1 $ is superior to athletes $ 2 $ and $ 3 $ . Since he is superior to all other athletes, he is likely to get the gold medal. - Athlete $ 2 $ is superior to athlete $ 3 $ . - Athlete $ 3 $ is not superior to any other athlete. Explanation of the fourth test case: There are $ n=6 $ athletes. - Athlete $ 1 $ is superior to athletes $ 3 $ , $ 4 $ , $ 6 $ . - Athlete $ 2 $ is superior to athletes $ 1 $ , $ 4 $ , $ 6 $ . - Athlete $ 3 $ is superior to athletes $ 2 $ , $ 4 $ , $ 6 $ . - Athlete $ 4 $ is not superior to any other athlete. - Athlete $ 5 $ is superior to athletes $ 1 $ , $ 2 $ , $ 3 $ , $ 4 $ , $ 6 $ . Since he is superior to all other athletes, he is likely to get the gold medal. - Athlete $ 6 $ is only superior to athlete $ 4 $ .