poj 3637 Shopaholic


//    ,  ! 
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAX = 20001;
int prices[MAX];

bool cmp(int a, int b)
{
     return a > b;
}

int main()
{
    int i, tc, num, ans;
    scanf("%d", &tc);
    while (tc--){
          scanf("%d", &num);
          ans = 0;
          for (i = 0;i < num; i++){
              scanf("%d", &prices[i]);
          }
          sort(prices, prices+num, cmp);
          for (i = 0; i < num; i++){
               if ((i+1) % 3 == 0)
                   ans += prices[i];
          }
          cout << ans << endl;
    }
    
    system("pause");
}