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());
for(int i=0;i<n-2;i++){
res+=2*x[i];
}
for(int i=n-2;i<n;i++){
res+=x[i];
}
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... |