SHARE
TWEET

Untitled

Prekzursil Jul 17th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. multiset<int> v;
  5. multiset<int>::iterator it;
  6.  
  7. int main()
  8. {
  9.     int n,x,c=0;
  10.     cin>>n;
  11.     for(int i=1;i<=n;i++)
  12.         cin>>x,v.insert(x);
  13.     while(v.size()>1)
  14.     {
  15.         int temp=0;
  16.         it=v.begin();
  17.         c+=*it,temp+=*it;
  18.         it++;
  19.         c+=*it,temp+=*it;
  20.         it=v.begin();
  21.         v.erase(it),it=v.begin(),v.erase(it);
  22.         v.insert(temp);
  23.     }
  24.     cout<<c;
  25. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top