题解 | #搬水果#
搬水果
https://www.nowcoder.com/practice/e4c775b0f3ee42a4bb72c26d2e1eef8a
#include <bits/stdc++.h> using namespace std; int main() { int n,m; while(cin>>n) { if(!n) break; priority_queue<int,vector<int>,greater<int>> myQueue; while(n--){ cin>>m; myQueue.push(m); } int res=0; while(myQueue.size()>1){ int a=myQueue.top(); myQueue.pop(); int b=myQueue.top(); myQueue.pop(); res+=a+b; myQueue.push(a+b); } cout<<res<<endl; } return 0; }