#K15871. Overall Tournament Winner
Overall Tournament Winner
Overall Tournament Winner
You are given an integer \(n\) representing the number of participants in a tournament. Each participant has an associated skill level. In the first round, a sequence of \(m\) matches is provided, each match given by a pair of 1-indexed participant indices \((x, y)\). The winner of a match is the participant with the higher skill level. After the first round, subsequent rounds are automatically organized by pairing consecutive players (i.e. the first with the second, the third with the fourth, etc.) until only one participant remains. Your task is to simulate the rounds and determine the overall tournament winner's skill level.
More formally, let \(S = [s_1, s_2, \dots, s_n]\) be the list of skill levels. In each round, for every match \((x,y)\) where \(1 \le x, y \le |S|\), the winner is \(\max(s_x, s_y)\). After all matches in the round have been simulated, the winners form the new skill level list \(S'\). If \(|S'| > 1\), new matches are generated as follows: \[ \text{matches} = \{ (1,2), (3,4), \dots \} \] until a single skill level remains. Print this skill level as the overall winner.
inputFormat
The input is given via standard input in the following format:
n s1 s2 ... sn m x1 y1 x2 y2 ... xm ym
Here, the first line contains an integer \(n\) (the number of participants). The second line contains \(n\) space-separated integers representing the skill levels. The third line contains an integer \(m\) denoting the number of matches in the first round. The following \(m\) lines each contain two space-separated integers \(x\) and \(y\), representing a match between the \(x\)-th and \(y\)-th participant.
outputFormat
Output a single integer, the overall winner's skill level, to standard output.
## sample4
4 3 7 5
3
1 3
2 4
3 4
7