合并果子

#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
    cin>>n;
  priority_queue<int,vector<int>,greater<int>> heap;
    while(n--){
        int x;
        cin>>x;
        heap.push(x);
    }
    int res=0;
    while(heap.size()>1){
     int a=heap.top();
     heap.pop();
     int b=heap.top();
     heap.pop();
    res+=a+b;
     heap.push(a+b);
    }
    cout<<res<<endl;
    return 0;
}

 

 

posted @ 2023-05-23 20:09  艾鑫4646  阅读(7)  评论(0编辑  收藏  举报