a53

Interclasari

a53
Oct 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4. priority_queue<int> Q;
  5.  
  6. int main()
  7. {
  8. int i,x,y,n,sol=0;
  9. cin>>n;
  10. for(i=1;i<=n;++i)
  11. cin>>x,Q.push(-x);
  12. while(--n)
  13. {
  14. x=-Q.top();
  15. Q.pop();
  16. y=-Q.top();
  17. Q.pop();
  18. x+=y;
  19. sol+=x;
  20. Q.push(-x);
  21. }
  22. cout<<sol;
  23. return 0;
  24. }
Add Comment
Please, Sign In to add comment