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