文章

85

粉丝

0

获赞

530

访问

11.0k

头像
合并果子 题解:
P1544 中南大学机试题
发布于2026年3月5日 18:13
阅读数 132

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin>>n;
    priority_queue <int,vector<int>,greater<int>> q;
    int x;
    for (int i=1;i<=n;i++) {
        cin>>x;
        q.push(x);
    }
    int ans =0;
    while (q.size()>1) {
        int a = q.top();q.pop();
        int b = q.top();q.pop();
        int c= a+b;
        q.push(c);
        ans+=c;
    }
    cout<<ans;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发