Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- priority_queue < int > Q;
- int main()
- {
- int cost = 0 ,n ,i ,x,y ,z;
- cin >> n;
- for (i = 1;i <= n; i++)
- {
- cin >> x;
- Q.push(-x);
- }
- for (i = 1;i < n; i++)
- {
- z = -Q.top();
- Q.pop();
- y = -Q.top();
- Q.pop();
- cost += (z + y);
- Q.push (-(z + y));
- }
- cout << cost;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement