pastebin

Paste #78852: Untitled ASCII paste by 61.142.209.146

#include <stdio.h>
#define MAX 20001
int main(){
	int data[MAX];
	int i,j,n,tem;
	long long temp,sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&data[i]);
	if(1==n){
		printf("%d\n",data[0]);
		return ;
	}
	for(i=1;i<n;i++){
		temp = data[i];
		for(j=i-1;j>=0 && data[j]>temp;j--)
			data[j+1] = data[j];
		data[j+1] = temp;
	}
	sum = 0;
	temp = data[0];
	j = 1;
	while(j<n-1){
		if(data[j+1] < temp){
			tem = temp;
			temp = data[j+1];	
			data[j+1] = tem;
		}
		else{
			temp += data[j];
			sum += temp;
			j++;
		}
	}
	printf("%ld\n",sum+temp+data[n-1]);
 	return 0;
}

Private
Wrap long lines

3 + 4 =