hdu 1678 优先队列
水题,理解题意后不难想到,只要对所有物品排个序,然后依次从小到大,三个三个地拿即可。
/*
* hdu1678/win.cpp
* Created on: 2011-10-1
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;
void work();
int main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
work();
return 0;
}
void work() {
int T;
scanf("%d", &T);
while (T--) {
int n, temp, ans = 0;
scanf("%d", &n);
priority_queue<int, vector<int>, greater<int> > pq;
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
pq.push(temp);
}
if (n % 3 != 0) {
pq.pop();
n--;
}
if (n % 3 != 0) {
pq.pop();
n--;
}
while (!pq.empty()) {
ans += pq.top();
pq.pop();
pq.pop();
pq.pop();
}
printf("%d\n", ans);
}
}