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