题解 | #搬水果#
搬水果
https://www.nowcoder.com/practice/e4c775b0f3ee42a4bb72c26d2e1eef8a
//1+2 3+9 12
#include <iostream>
#include <queue>
using namespace std;
int main() {
int n;
while (cin >>n) {
if(n==0)break;
priority_queue<int,vector<int>,greater<>> q;
for(int i=1;i<=n;i++)
{
int t;cin>>t;q.push(t);
}
int answer=0;
while(q.size()>1)
{
int a,b;
a=q.top();q.pop();
b=q.top();q.pop();
int c=a+b;
answer+=c;
q.push(c);
}
cout<<answer<<endl;
}
}
查看7道真题和解析
快手公司福利 1244人发布