#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
struct rule{
bool operator() (const int &a,const int &b){
return a>b;//优先队列 从小到大排列规则
}
};
int Count=0;
int temp;
int main(){
freopen("input.txt","r",stdin);
priority_queue<int,vector<int>,rule> qu;//使用优先队列
int n,buf;
scanf("%d",&n);
while(scanf("%d",&buf)==1){
qu.push(buf);
}
while(qu.size()>1){
temp=0;
temp+=qu.top();//将最小的两个出队
qu.pop();
temp+=qu.top();
qu.pop();
Count+=temp;//计数
qu.push(temp);//求和再入队
}
printf("%d",Count);
/*while(!qu.empty()){
cout<<qu.top()<<" ";
qu.pop();
}*/
return 0;
}
18-03-09 P1090 合并果子
最新推荐文章于 2024-07-29 01:31:58 发布
