POJ - 3253 Fence Repair
#include<cstdio>
#include<queue>
using namespace std;
typedef long long ll;
int main()
{
int n;while(scanf("%d",&n)!=EOF){
priority_queue<ll,vector<ll>,greater<ll>>q;//最小优先for(int i=0;i<n;++i){
int x;scanf("%d",&x);q.push(x);}ll sum=0;while(!q.empty()){
int a=q.top();q.pop();int b=q.top();q.pop();sum=sum+a+b;if(q.empty()) break;q.push(a+b);}printf("%lld\n",sum);}return 0;
}