acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • 简单有批注

    #include <bits/stdc++.h> using namespace std; int n; int a[10010]; priority_queue<int, vector<int>, greater<int>>q; //堆顶元素 q.top(); int main(){ cin >> n; for(int i = 1; i <= n; i ++ ){ cin >> a[i]; q.push(a[i]); } int ans = 0; while(q.size() > 1){ int x = q.top(); q.pop(); int y = q.top(); q.pop(); ans += x + y; q.push(x + y); } cout << ans << endl; return 0; }

    userId_undefined

    我是你爹

    倔强青铜
    6阅读
    0回复
    0点赞
首页