SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. priority_queue < int > q;
  7.  
  8. int main()
  9. {
  10.     int i, n, x, y, cost;
  11.     cin >> n;
  12.     for(i=1; i<=n; i++)
  13.     {
  14.         cin >> x;
  15.         q.push(-x);
  16.     }
  17.     cost = 0;
  18.     for(i=1; i<n; i++)
  19.     {
  20.         x=-q.top();
  21.         q.pop();
  22.         y=-q.top();
  23.         q.pop();
  24.         cost+=x+y;
  25.         q.push(-(x+y));
  26.     }
  27.     cout << cost;
  28.  
  29.     return 0;
  30. }
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