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