## Maximum Median Matching Codechef Solution | MEDMAXMATCH | (100/100) FULL | Codechef July Lunchtime | AC Code

**odd**. For today’s practice session, they need to form

The

Let the happiness values of the **maximum** possible value of the **median of**

**Note:** The median of a odd-sized list of integers is the middle number when they are sorted. For example, the median of

### Input Format

- The first line of input will contain a single integer
T , denoting the number of test cases. - Each test case consists of three lines of input.
- The first line of each test case contains a single integer
N . - The second line of each test case contains
N space-separated integersA1,A2,…,AN — the happiness values of the boys. - The third line of each test case contains
N space-separated integersB1,B2,…,BN — the happiness values of the girls.

### Output Format

For each test case, output on a new line the maximum possible median happiness of the

### Constraints

1≤T≤3⋅104 1≤N<3⋅105 N is odd1≤Ai,Bi≤109 for each validi - The sum of
N across all test cases won’t exceed3⋅105 .

### Sample Input 1 * *

```
3
1
10
25
3
1 6 6
2 2 7
5
10 4 93 5 16
4 34 62 6 26
```

### Sample Output 1 * *

```
35
8
50
```

### Explanation

**Test case 1**

There is only one boy and one girl, so they must be paired with each other. The happiness value of the pair is

**Test case 2**

Pair

**Test case 3**

One way of achieving a median of

- Pair
A1 withB3 , for a happiness of10+62=72 - Pair
A2 withB4 , for a happiness of4+6=10 - Pair
A3 withB5 , for a happiness of93+26=119 - Pair
A4 withB1 , for a happiness of5+4=9 - Pair
A5 withB2 , for a happiness of16+34=50

The happiness values are

` ````
```void solve()
{
ll oo = 1, n;
if (oo != 1)
{
ll ji = -1;
}
else
{
cin >> n;
}
vector y(n);
vector x(n);
for (ll i = 0; i < n; i++)
cin >> x[i];
sort(x.begin(), x.end());
for (ll i = 0; i < n; i++)
cin >> y[i];
sort(y.begin(), y.end());
vector we;
for (ll i = n / 2; i < n; i++)
we.push_back(y[i]);
b = we;
we.clear();
for (ll i = n / 2; i < n; i++)
we.push_back(x[i]);
a = we;
n = a.size();
vector cty;
for (ll i = 0; i < n; i++)
{
cty.push_back(x[i] + y[n - 1 - i]);
}
sort(cty.begin(), cty.end());
cout << cty[0] << endl;
}

## 0 Comments