Created
December 29, 2015 22:25
-
-
Save nomarlo/0c00cb88d2eac33c17a0 to your computer and use it in GitHub Desktop.
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
/** | |
La idea de solución es tomar siempre los valoresminimos disponibles. | |
Para ello utilizamos una cola de prioridad(minima) y simplemente, | |
simulamos el proceso | |
**/ | |
#include <iostream> | |
#include <cmath> | |
#include <algorithm> | |
#include <queue> | |
#include <stack> | |
#include <sstream> | |
#include <map> | |
#include <set> | |
#include <queue> | |
#include <cstdio> | |
using namespace std; | |
struct compare | |
{ | |
bool operator()(const int& l, const int& r) | |
{ | |
return l > r; | |
} | |
}; | |
priority_queue<int, vector<int>,compare > PQ; | |
int n,res,aux; | |
int main(){ | |
scanf("%d",&n); | |
while(n){ | |
res=0; | |
while(n--){ | |
scanf("%d",&aux); | |
PQ.push(aux); | |
} | |
while(!PQ.empty()){ | |
int ax=PQ.top(); | |
PQ.pop(); | |
ax+=PQ.top(); | |
PQ.pop(); | |
if(!PQ.empty()) | |
PQ.push(ax); | |
res+=ax; | |
} | |
printf("%d\n",res); | |
scanf("%d",&n); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment