poj3637

水题,只要排好序后,从大到小每三个取一个,加起来就是答案。

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int maxn = 20002;

int main()
{
	//freopen("D:\\t.txt", "r", stdin);
	int t;
	scanf("%d", &t);
	while (t--)
	{
		int n;
		int good[maxn];
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d", &good[i]);
		sort(good, good + n);
		int ans = 0;
		int i = n % 3;
		for (;i < n; i += 3)
			ans += good[i];
		printf("%d\n", ans);
	}
	return 0;
}
posted @ 2011-02-01 13:54  金海峰  阅读(215)  评论(0编辑  收藏  举报