Skip to content

Instantly share code, notes, and snippets.

@ravichandrae
Created July 19, 2016 11:33
Show Gist options
  • Save ravichandrae/fa34fa201b6c5b94894cf87a3ea6ba21 to your computer and use it in GitHub Desktop.
Save ravichandrae/fa34fa201b6c5b94894cf87a3ea6ba21 to your computer and use it in GitHub Desktop.
This is my solution for the Codechef problem https://www.codechef.com/problems/ANUBTG
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int t;
cin >> t;
while( t-- ) {
int n;
cin >> n;
vector<int> prices(n);
int i;
for(i = 0; i < n; i++)
{
cin >> prices[i];
}
sort( prices.begin(), prices.end(), greater<int>());
int amt = 0;
for(i = 0; i <= n-2; i+=4)
{
amt += prices[i]+prices[i+1];
}
if(i == n-1)
amt += prices[n-1];
cout << amt << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment