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