提交时间:2019-11-09 17:28:04
运行 ID: 2151
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<stack> #include<vector> using namespace std; long long n,sum,temp; priority_queue<int>q; int main() { cin>>n; for(int i=0;i<n;i++) { cin>>temp; q.push(-temp); } int k=2; temp=0-q.top(); q.pop(); //cout<<temp<<endl; temp-=q.top(); q.pop(); sum+=temp; //cout<<temp<<endl; q.push(-temp); while(q.empty()!=1) { temp=0-q.top(); q.pop(); //cout<<temp<<endl; //cout<<q.empty()<<endl; if(q.empty()==1) { break; } temp-=q.top(); sum+=temp; //cout<<temp<<endl; q.pop(); q.push(-temp); } cout<<sum; }