#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,que[10005],fr=-1,la,ans,tong[1005];
int wd[10005];
void read(int &x){
int f=1;x=0;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
x*=f;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
read(wd[i]);
tong[wd[i]]++;
}
int cnt=0;
for(int i=1;i<=1000;i++)
{
for(int j=1;j<=tong[i];j++)
wd[++cnt]=i;
}
int i=0;
for(int j=1;j<n;j++)
{
if(la==0)
que[la++]=wd[++i]+wd[++i];
else{
i++;fr++;
if(wd[i]<que[fr]&&i<=n||fr==la)
{
que[la]+=wd[i];
if(i==n) i=n+1;
fr--;
}
else{
que[la]+=que[fr];
i--;
}
i++;fr++;
if(wd[i]<que[fr]&&i<=n||fr==la)
{
que[la]+=wd[i];
if(i==n) i=n+1;
fr--;
}
else{
que[la]+=que[fr];
i--;
}
la++; //cout<<j<<' '<<que[la-1]<<endl;
}
ans+=que[la-1];
}
cout<<ans;
return 0;
}
06-04
581
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
07-16
08-21
1694
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
12-04
1584
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountBlack.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交