Advertisement
ShafiulAzim

uva 10954

Feb 2nd, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,x;
  6. while(1)
  7. {
  8. int total=0,cost=0;
  9. cin>>n;
  10. if(n==0)
  11. return 0;
  12. priority_queue<int>pq;
  13. while(n--)
  14. {
  15.  
  16. cin>>x;
  17. x=x*(-1);
  18. pq.push(x);
  19. }
  20.  
  21. while(pq.size()!=1)
  22. {
  23. total=pq.top();
  24. pq.pop();
  25. total+=pq.top();
  26. pq.pop();
  27. cost+=total;
  28. pq.push(total);
  29. }
  30. cout<<(cost*(-1))<<endl;
  31.  
  32. }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement