提交时间:2024-08-20 20:20:45

运行 ID: 169928

#include<cstdio> #include<queue> #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; }