All pastes #278777 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2006-12-14 12:02 UTC
rendered paste body
/* dunno to use it as an ascending queue so using it as descending queue by pushing -ve numbers*/#include<iostream>#include<queue>using namespace std;int main(){	int N;	long num,a,b,sum=0;	priority_queue<long> P;	scanf("%d",&N);	for(int i=0;i<N;i++)	{		scanf("%ld",&num);		if(num!=0)			P.push(-num);	}		while(P.size()>1)	{		a = -P.top();		P.pop();		b = -P.top();		P.pop();		P.push(-(a+b));		sum += a+b;		//cout<<sum<<"\n";	}	cout<<sum<<"\n"; // sum of internal nodes is the answer, rite ?	return 0;}