Turtle and Piggy Are Playing a Game 2

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 1im1, 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 1im1, 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) (1t104). 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) (2n105) — 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) (1ai105) — 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;
}
  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值