牢大 • 7天前
using namespace std; priority_queue<int, vector, greater> q; int ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
q.push(t);
}
while (q.size() > 1) {
int a, b;
a = q.top();
q.pop();
b = q.top();
q.pop();
ans += a + b;
q.push(a + b);
}
cout << ans;
}
评论:
请先登录,才能进行评论