Turtle and Piggy Are Playing a Game 2
Problem
Turtle and Piggy are playing a game on a sequence. They are given a sequence a 1 , a 2 , … , a n a_1,a_2,…,a_n a1,a2,…,an, and Turtle goes first. Turtle and Piggy alternate in turns (so, Turtle does the first turn, Piggy does the second, Turtle does the third, etc.).
The game goes as follows:
- Let the current length of the sequence be m. If m = 1 m=1 m=1, the game ends.
- If the game does not end and it’s Turtle’s turn, then Turtle must choose an integer i such that 1 ≤ i ≤ m − 1 1≤i≤m−1 1≤i≤m−1, set ai to m a x ( a i , a i + 1 ) max(a_i,a_{i+1}) max(ai,ai+1), and remove $a_{i+1}.
- If the game does not end and it’s Piggy’s turn, then Piggy must choose an integer i
such that 1 ≤ i ≤ m − 1 1≤i≤m−1 1≤i≤m−1, set ai to m i n ( a i , a i + 1 ) min(a_i,a_{i+1}) min(ai,ai+1), and remove $a_{i+1}.
Turtle wants to maximize the value of a 1 a_1 a1 in the end, while Piggy wants to minimize the value of a 1 a_1 a1 in the end. Find the value of a 1 a_1 a1 in the end if both players play optimally.
You can refer to notes for further clarification.
Input
Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 ) (1≤t≤10^4) (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n n n ( 2 ≤ n ≤ 1 0 5 ) (2≤n≤10^5) (2≤n≤105) — the length of the sequence.
The second line of each test case contains n integers a 1 , a 2 , … , a n a_1,a_2,…,a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 5 ) (1≤a_i≤10^5) (1≤ai≤105) — the elements of the sequence a.
It is guaranteed that the sum of n over all test cases does not exceed 1 0 5 10^5 105.
Output
For each test case, output a single integer — the value of a 1 a_1 a1 in the end if both players play optimally.
Example
Input
5
2
1 2
3
1 1 2
3
1 2 3
5
3 1 2 2 3
10
10 2 5 2 7 9 2 5 10 7
Output
2
1
2
2
7
Note
Code
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+10;
ll a[N];
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
for(ll i=1;i<=n;i++)
cin>>a[i];
//乌龟先
sort(a+1,a+n+1);
//乌龟:最大值;小猪:最小化
cout<<a[n/2+1]<<endl;
}
return 0;
}