题解 | #搬水果#
搬水果
https://www.nowcoder.com/practice/e4c775b0f3ee42a4bb72c26d2e1eef8a
#include <stdio.h>
#include <queue>
using namespace std;
int main() {
int n;
scanf("%d", &n);
priority_queue<int> pqueue;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
pqueue.push(-x);
}
int wpl = 0;
while (pqueue.size() > 1) {
int right = pqueue.top();
pqueue.pop();
int left = pqueue.top();
pqueue.pop();
int weight = left + right;
wpl += weight;
pqueue.push(weight);
}
printf("%d\n", -wpl);
return 0;
}