Advertisement
Saleh127

UVA 10954 / Data Structure

Mar 15th, 2022
1,162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. /***
  2.  created: 2022-03-15-22.07.58
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7. #define ll long long
  8. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  9. #define get_lost_idiot return 0
  10. #define nl '\n'
  11.  
  12. int main()
  13. {
  14.     ios_base::sync_with_stdio(0);
  15.     cin.tie(0);
  16.     cout.tie(0);
  17.  
  18.     ll n;
  19.  
  20.     while(cin>>n && n)
  21.     {
  22.         ll i,j,k=0,l=0;
  23.  
  24.         priority_queue <ll, vector<ll>, greater<ll>> q;
  25.  
  26.         for(i=0;i<n;i++)
  27.         {
  28.             cin>>j;
  29.  
  30.             q.push(j);
  31.         }
  32.  
  33.  
  34.         while(q.size()!=1)
  35.         {
  36.             i=q.top();
  37.             q.pop();
  38.             j=q.top();
  39.             q.pop();
  40.  
  41.             k+=(i+j);
  42.  
  43.             q.push(i+j);
  44.         }
  45.  
  46.         cout<<k<<nl;
  47.     }
  48.  
  49.     get_lost_idiot;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement