This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
#define endl ('\n')
using namespace std;
void solve() {
int n;
cin>>n;
vector<int>x(n);
vector<int>y;
int res=0;
for(int i=0;i<n;i++){
cin>>x[i];
}
if(n==1){
cout<<0<<endl;
return;
}
sort(x.begin(),x.end());
y.push_back(x[n-1]);
for(int i=0;i<n-1;i++){
y.push_back(x[i]);
}
for(int i=0;i<n-1;i++){
res+=(y[i]+y[i+1]);
}
cout<<res<<endl;
}
int32_t main(){
fast
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |