Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
1A 贴代码#include<algorithm> #include<iostream> #include<cstdio> #include<cmath> using namespace std; const int maxn=1000001; int n,a[maxn],i,j,k,b; long long sum,ans=0; int main() { scanf("%d",&n); int l=n; for(i=1;i<=n;++i)scanf("%d",&a[i]); sort(a+1,a+n+1); k=1; for(i=1;i<n;++i) { sum=a[k]+a[k+1]; ans+=sum; k+=2; b=k; while(a[k]<sum&&k<=l)k++; for(j=l+1;j>k;--j)a[j]=a[j-1]; a[k]=sum; l++; k=b; } printf("%lld\n",ans); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator