题解 | #搬水果#

搬水果

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;

}

全部评论

相关推荐

07-01 23:23
郑州大学 Java
否极泰来来来来:牛客迟早有高三的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务