1 3 1 2 9
15
//合并果子堆 #include<iostream> #include<queue> #include<algorithm> using namespace std; struct node { int x; }; bool operator<(node a,node b) { return a.x>b.x; } int main() { int N; cin>>N; while(N--) { priority_queue<node>q; node temp; int n; cin>>n; while(n--) { cin>>temp.x; q.push(temp); } long long ans=0; while(q.size()>1) { node a=q.top(); q.pop(); node b=q.top(); q.pop(); ans+=a.x+b.x; a.x+=b.x; q.push(a); } cout<<ans<<endl; } }
原文:http://www.cnblogs.com/tt-t/p/5022610.html