NOIPTG2004合并果子

//堆
#include <bits/stdc++.h> using namespace std; #define fr(i,m,n) for(int i=m;i<=n;i++)int x,y,n,t,ans; priority_queue< int,vector<int>,greater<int> > h; int main() { ios::sync_with_stdio(false); cin >> n; fr(i,1,n){ cin >> t; h.push(t); } fr(i,1,n-1){ x = h.top(); h.pop(); y = h.top(); h.pop(); ans += x + y; h.push(x + y); } cout << ans; return 0; }

猜你喜欢

转载自www.cnblogs.com/phemiku/p/11618501.html