最开始我看到这题以为很难,想一想......排序啊!每次找最小的两堆合起来就可以!但每次都要排序,很麻烦。于是我用了.......
优先队列!AC代码:
#includeusing namespace std; int n,x,ans; priority_queue ,greater >q; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>x,q.push(x); while(q.size()>=2){ int a=q.top(); q.pop(); int b=q.top(); q.pop(); ans+=a+b; q.push(a+b); } cout<


![P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G题解(优先队列) P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G题解(优先队列)](http://www.mshxw.com/aiimages/31/983601.png)
