题解 | 搬水果
搬水果
https://www.nowcoder.com/practice/e4c775b0f3ee42a4bb72c26d2e1eef8a
#include <stdio.h>
#include <queue>
using namespace std;
int main() {
int n ;
while (scanf("%d", &n) != EOF && n != 0) {
priority_queue<int> pqueue;
int fruit;
for (int i = 0; i < n; i++) {
scanf("%d", &fruit);
pqueue.push(-1 * fruit);
}
int tili = 0;
while (pqueue.size() >= 2) {
int fruit1 = pqueue.top();
pqueue.pop();
int fruit2 = pqueue.top();
pqueue.pop();
tili += fruit1 + fruit2;
pqueue.push(fruit1 + fruit2);
}
printf("%d\n", -1*tili);
}
}