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>
using namespace std;
const int MAXN = 1e5 + 25;
int arr[MAXN];
int main () {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
if (n == 1) {
cout << "0\n";
return 0;
}
long long sum = 0;
sort(arr + 1, arr + n + 1);
for (int i = 1; i < n - 1; i++) sum += 2 * arr[i];
sum += arr[n - 1] + arr[n];
cout << sum << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |