codechef Chef and easy problem

Problem Description

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 Ttest 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 A1A2, ..., 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 ≤ 109
  • Subtask 1 (35 points): T = 10, 1 ≤ N ≤ 1000
  • Subtask 2 (65 points): T = 10, 1 ≤ N ≤ 105

Example

Input:

2 3 1 2 3 3 1 2 1

Output:

4 3

题解

贪心。注意lld。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int T,n,a[100002];
ll ans;
void work()
{
	scanf("%d",&n);
	ans=0;
	int i;
	for(i=1;i<=n;i++)
	   scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(i=n;i>=1;i-=2)
	   ans+=a[i];
	printf("%lld\n",ans);
}
int main()
{
	scanf("%d",&T);
	while(T--) work();
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值