zoukankan      html  css  js  c++  java
  • AcWing 148. 合并果子

    #include <iostream>
    #include <algorithm>
    #include <queue>
    using namespace std;
    int main() {
        int n;
        scanf("%d", &n);
        priority_queue<int, vector<int>, greater<int>> heap;
        while (n -- ) {
            int x;
            scanf("%d", &x);
            heap.push(x);
        }
        int res = 0;
        while (heap.size() > 1) {
            int a = heap.top();
            heap.pop();
            int b = heap.top();
            heap.pop();
            res += a + b;
            heap.push(a + b);
        }
        printf("%d
    ", res);
        return 0;
    }
  • 相关阅读:
    JAVA变量的作用域
    SQLite
    ajax
    浏览器调试
    SQL链接
    Computer
    Sql知识点总结
    Web Socket
    秒杀
    副业
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/11909465.html
Copyright © 2011-2022 走看看