1107:搬水果

#include<iostream>
#include<queue>
using namespace std;

int main()
{
	int n;
	while(cin>>n&&n)
	{
		priority_queue<int,less<int>> PQ;
		for(int i=0;i<n;++i)
		{
			int temp;
			cin>>temp;
			PQ.push(temp);
		}
		int ret=0;
		while(PQ.size()>1)
		{
			int temp=0;
			temp+=PQ.top();
			PQ.pop();
			temp+=PQ.top();
			PQ.pop();
			PQ.push(temp);
			ret+=temp;
		}
		cout<<ret<<endl;
	}
	return 0;
}

 

posted @ 2012-04-13 11:19  dupuleng  阅读(86)  评论(0)    收藏  举报