3404

/*
贪心,和1700很相似

这题上次在URAL的一次比赛中碰到了,一直过不去,不知道贪的怎么不对
现在又碰大了,原理是最小的一对人交替的来传递棒,但是又个地方需要特别注意
就是最大的一对中的较小的和最小的一对较大的比较的话,如果等于了,那么就必须小最小的和最大的传了
这个例子 5 6 6 7 很清楚
如果按照那个方法是  6 5 7 6 6 = 30
但是最好的方法是 7 5 6 5 6 = 29,好好想想这个,挺有意思的

错了,应该是d[0]+d[i-1]>=2*d[1]成立的时候才行
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
int data[55];
int N;
int main()
{
	read;
	write;
	int ans ;
	while(scanf("%d",&N)==1)
	{
		for(int i=0;i<N;i++)
			scanf("%d",data+i);
		sort(data,data+N);
		ans = 0;
		for(int i=N-1;i>=0;)
		{
			if(i+1==1)
			{
				ans+=data[0];break;
			}
			if(i+1==3)
			{
				ans += data[2]+data[0]+data[1];
				break;
			}
			else if(i+1==2)
			{
				ans += data[1];
				break;
			}
			else
			{
				if(data[i-1]+data[0]>=2*data[1]) 
				{
					ans += data[i]+data[1]+data[0]+data[1];
					i-=2;
				}
				else
				{
					ans += data[i]+data[0];
					i--;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

posted @ 2011-04-21 13:31  AC2012  阅读(144)  评论(0编辑  收藏  举报