You are given an array containing 2 \times n elements.You have to partition the numbers…
- User
You are given an array containing 2 \times n elements.You have to partition the numbers in to n pairs with the property that partition minimize the maximum sum of a pair. Input First line contains T number of test cases. Next line contain N number of pairs. Next line contain 2*N positive integers represent elements of an array. Output For each test case print minimum possible maximum sum of a pair. CONSTRAINTS 1 ≤ T ≤ 100 1 ≤ N ≤ 100000 1 ≤ A[i] ≤ 100000
SAMPLE INPUT 1 3 5 6 2 3 9 8
SAMPLE OUTPUT 11
Explanation
In sample input possible partitions are ((5,6) , (9,2) , (8,3)) and pair sum for these partitons are (11,11,11) so minimum possible maximum sum is 11. Other possible pairs are ((3,2) , (9,5) , (8,6)) so here minimum possible maximum sum is 14. So 11 is minimum possible maximum sum from all possible pair of partitions.
Assistant
pythondef main(): import sys input = sys.stdin.read().split() ptr = 0 T = int(input[ptr]) ptr += 1 for _ in range(T): N = int(input[ptr]) ptr += 1 arr = list(map(int, input[ptr:ptr + 2*N])) ptr += 2*N arr.sort() max_sum = 0 for i in range(N): s = arr[i] + arr[2*N - 1 - i] if s > max_sum: max_sum = s print(max_sum) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.