Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // STRJOIN
- #include <iostream>
- #include <cstring>
- using namespace std;
- #include <fstream>
- #include <cstdio>
- #include <cmath>
- #include <ctime>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <functional>
- #include <deque>
- #include <numeric>
- #include <set>
- #include <climits>
- #include <utility>
- #include <map>
- #include <algorithm>
- #define INF 987654321
- #define MOD 1000000007
- typedef long long ll;
- typedef unsigned long long ull;
- inline int max( int x, int y ){ return x > y ? x : y ; }
- inline int min( int x, int y ){ return x < y ? x : y ; }
- inline ll max( ll x, ll y ){ return x > y ? x : y ; }
- inline ll min( ll x, ll y ){ return x < y ? x : y ; }
- inline ull max( ull x, ull y ){ return x > y ? x : y ; }
- inline ull min( ull x, ull y ){ return x < y ? x : y ; }
- int main(){
- int TC, N, eat, tmp1, tmp2;
- int ans = 0;
- scanf("%d", &TC);
- while( TC-- ){
- ans = 0;
- scanf("%d", &N);
- vector<int> Len(N);
- priority_queue<int, vector<int>, greater<int> >pq;
- for( int i=0; i<N; ++i ){
- scanf("%d", &Len[i]);
- pq.push( Len[i] );
- }
- while( pq.size() > 1 ){
- tmp1 = pq.top();
- pq.pop();
- tmp2 = pq.top();
- pq.pop();
- ans += tmp1+tmp2;
- pq.push( tmp1+tmp2 );
- }
- printf("%d\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement