提交时间:2024-08-19 22:49:50
运行 ID: 168122
#include<bit/stdc++.h> #define pt p.top(); #define pp p.pop(); #define pu(a) p.push(a); using namespace std; int n,i,x,y,ans; priority_queue<int,vector<int>,greater<int> > p; int main() { scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&x); p.push(x); } while(p.size()!=1) { x=pt pp y=pt pp ans+=x+y; p.push(x+y); } printf("%d",ans); return 0; }