Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. int n,x;
  7. priority_queue<int,vector<int>,greater<int>>q;
  8.  
  9. int main()
  10. {
  11. cin>>n;
  12. for(int i=1;i<=n;++i)
  13. {
  14. cin>>x;
  15. q.push(x);
  16. }
  17. int s=0;
  18. while(q.size()>1)
  19. {
  20. int a=q.top();
  21. q.pop();
  22. int b=q.top();
  23. q.pop();
  24. q.push(a+b);
  25. s+=a+b;
  26. }
  27. cout<<s;
  28.  
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement