Channel
Test instructions: According to that recursion, find the law can.
Code:
#include <cstdio>#include<cstring>#include<vector>#include<queue>#include<algorithm>using namespaceStd;typedefLong LongLl;inlineBOOLRdint&ret) { CharCintSGN; if(c = GetChar (), c = = EOF)return false; while(c! ='-'&& (C <'0'|| C >'9')) C =GetChar (); SGN= (c = ='-') ? -1:1; RET= (c = ='-') ?0: (C-'0'); while(c = GetChar (), C >='0'&& C <='9') ret = RET *Ten+ (C-'0'); RET*=SGN; return true;} Priority_queue<ll,vector<ll>, greater<ll> >Q;intMain () {intT; scanf ("%d", &T); while(t-->0) { intN; Rd (n); while(!q.empty ()) Q.pop (); for(inti =0; I < n; ++i) {intx; rd (x); Q.push (x); } ll ans=0; while(!Q.empty ()) {ll x=q.top (); Q.pop (); if(Q.empty ()) Break; ll y=q.top (); Q.pop (); Ans+ = x +y; Q.push (x+y); } printf ("%i64d\n", ans); } return 0;}
View Code
Havermann tree HDU 5350 MZL ' s munhaff function