Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A 贴代码

Posted by louchiheng at 2016-04-07 17:58:56 on Problem 3253
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator