从大到小排好序直接把每三个的最后一个加起来...
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 int a[20005]; 6 7 bool cmp(int a, int b) 8 { 9 return a > b; 10 } 11 12 int main() 13 { 14 int t; 15 cin >> t; 16 while(t--) 17 { 18 int n; 19 cin >> n; 20 for(int i=0; i<n; i++) 21 cin >> a[i]; 22 sort(a, a+n, cmp); 23 int sum=0; 24 for(int i=2; i<n; i+=3) 25 sum += a[i]; 26 cout << sum << endl; 27 } 28 return 0; 29 }