Advertisement
Guest User

Untitled

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