Connect Ropes Time : Space : 12345678910111213int Solution::solve(vector<int> &A) { int res = 0; priority_queue<int, vector<int>, greater<int>> q; for(auto a : A) q.push(a); while(q.size() > 1) { auto a = q.top(); q.pop(); auto b = q.top(); q.pop(); res += a + b; q.push(a + b); } return res;}