Chef and Roma are playing a game. Rules of the game are quite simple. Initially there…
- User
Chef and Roma are playing a game. Rules of the game are quite simple. Initially there are N piles of stones on the table. In each turn, a player can choose one pile and remove it from the table. Each player want to maximize the total number of stones removed by him. Chef takes the first turn.
Please tell Chef the maximum number of stones he can remove assuming that both players play optimally. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N denoting the number of piles. The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
Output For each test case, output a single line containg the maximum number of stones that Chef can remove.
Constraints
1 ≤ Ai ≤ 10^9 Example
Input: 2 3 1 2 3 3 1 2 1
Output: 4 3
Assistant
pythont = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) a_sorted = sorted(a, reverse=True) total = sum(a_sorted[i] for i in range(0, n, 2)) print(total)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.