Skip to content

Commit cec623d

Browse files
committed
Codechef: Easy Problems
1 parent 969f154 commit cec623d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Chef and Roma are playing a game. Rules of the game are quite simple.
2+
# Initially there are N piles of stones on the table.
3+
# In each turn, a player can choose one pile and remove it from the table.
4+
# Each player want to maximize the total number of stones removed by him.
5+
# Chef takes the first turn.
6+
#
7+
# Please tell Chef the maximum number of stones he can remove assuming that both players play optimally.
8+
#
9+
# Input
10+
# The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
11+
#
12+
# The first line of each test case contains a single integer N denoting the number of piles.
13+
#
14+
# The second line contains N space separated integers A1, A2, ..., AN denoting the number of stones in each pile.
15+
#
16+
# Output
17+
# For each test case, output a single line containg the maximum number of stones that Chef can remove.
18+
#
19+
# Constraints
20+
# 1 ≤ Ai ≤ 109
21+
# Subtask 1 (35 points): T = 10, 1 ≤ N ≤ 1000
22+
# Subtask 2 (65 points): T = 10, 1 ≤ N ≤ 105
23+
#
24+
# Example
25+
# Input:
26+
# 2
27+
# 3
28+
# 1 2 3
29+
# 3
30+
# 1 2 1
31+
#
32+
# Output:
33+
# 4
34+
# 3
35+
36+
for _ in range(int(input())):
37+
n = int(input())
38+
array = [int(i) for i in input().split()]
39+
array.sort()
40+
41+
stones1 = sum([array[i] for i in range(0, n, 2)])
42+
stones2 = sum([array[i] for i in range(1, n, 2)])
43+
print(max(stones2, stones1))

0 commit comments

Comments
 (0)