12345678910111213141516171819202122232425262728 |
- //
- // Created by jal on 2019-05-02.
- //
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int n;
- while(cin >> n){
- priority_queue<int, vector<int>, greater<int>>Q;
- for(int i = 0; i < n; i++){
- int x;
- cin >> x;
- Q.push(x);
- }
- int cnt = 0;
- for(int i = 1; i < n; i++){
- int a = Q.top();
- Q.pop();
- int b = Q.top();
- Q.pop();
- int c = a + b;
- cnt += c;
- Q.push(c);
- }
- cout << cnt << endl;
- }
- }
|