joj 2657 简单贪心

/* 
  Name: joj 2657 打水问题 
  Author:UnimenSun 
  Date: 4/07/11 21:54 
  Description: 简单贪心 
*/  

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> wait;
int n;


int main()
{
	int i;
	int sum1, sum2;
	while(cin>>n)
	{
		for(i=0; i<n; ++i)
		{
			int temp;
			cin>>temp;
			wait.push_back(temp);
		}	
		sort(wait.begin(), wait.end());
		sum1 = 0, sum2 = 0;
		for(i=1; i<n; ++i)
		{
			sum2 += wait[i-1];
			sum1 += sum2;		
		}
		wait.clear();
		cout<<sum1<<endl;
	}
	return 0;
}


你可能感兴趣的:(joj 2657 简单贪心)