Created
July 19, 2016 11:33
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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