#include<bits/stdc++.h>
using namespace std;
const int N = 100009;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int ans = 0;
while (a.size() > 1) {
sort(a.begin(), a.end());
int res = a[0] + a[1];
ans += res;
a[0] = res;
a.erase(a.begin() + 1);
}
cout << ans << endl;
return 0;
}
稍微扫了一眼题解,没看到这种做法,一时间只想到了排序,没想到用优先队列,但居然能ac..,应该还是数据太水了