You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
377 B
29 lines
377 B
#include<bits/stdc++.h>
|
|
using namespace std;
|
|
int main () {
|
|
int n,i,j,sum=0,t;
|
|
scanf("%d",&n);
|
|
int a[n];
|
|
for(i=0; i<n; i++)
|
|
scanf("%d",&a[i]);
|
|
while(n!=1) {
|
|
for(i=0; i<n-1; i++)
|
|
for(j=i+1; j<n; j++) {
|
|
if(a[i]<a[j]) {
|
|
int t=a[i];
|
|
a[i]=a[j];
|
|
a[j]=t;
|
|
}
|
|
}
|
|
t=a[n-1]+a[n-2];
|
|
sum+=t;
|
|
a[n-2]=t;
|
|
n--;
|
|
}
|
|
printf("%d\n",sum);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|