Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // STRJOIN
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6. #include <fstream>
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <vector>
  11. #include <stack>
  12. #include <queue>
  13. #include <functional>
  14. #include <deque>
  15. #include <numeric>
  16. #include <set>
  17. #include <climits>
  18. #include <utility>
  19. #include <map>
  20. #include <algorithm>
  21. #define INF 987654321
  22. #define MOD 1000000007
  23. typedef long long ll;
  24. typedef unsigned long long ull;
  25. inline int max( int x, int y ){ return x > y ? x : y ; }
  26. inline int min( int x, int y ){ return x < y ? x : y ; }
  27. inline ll max( ll x, ll y ){ return x > y ? x : y ; }
  28. inline ll min( ll x, ll y ){ return x < y ? x : y ; }
  29. inline ull max( ull x, ull y ){ return x > y ? x : y ; }
  30. inline ull min( ull x, ull y ){ return x < y ? x : y ; }
  31.  
  32.  
  33. int main(){
  34.  
  35. int TC, N, eat, tmp1, tmp2;
  36. int ans = 0;
  37.  
  38. scanf("%d", &TC);
  39. while( TC-- ){
  40. ans = 0;
  41. scanf("%d", &N);
  42. vector<int> Len(N);
  43. priority_queue<int, vector<int>, greater<int> >pq;
  44. for( int i=0; i<N; ++i ){
  45. scanf("%d", &Len[i]);
  46. pq.push( Len[i] );
  47. }
  48.  
  49. while( pq.size() > 1 ){
  50. tmp1 = pq.top();
  51. pq.pop();
  52. tmp2 = pq.top();
  53. pq.pop();
  54. ans += tmp1+tmp2;
  55. pq.push( tmp1+tmp2 );
  56. }
  57. printf("%d\n", ans);
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement