1 条题解
-
0
使用最小堆反复合并两堆最轻的果子;只有一堆时无需合并,费用为0,避免访问不存在的第二堆。
#include <bits/stdc++.h> using namespace std; int main(){ios::sync_with_stdio(false);cin.tie(nullptr); int n;cin>>n;priority_queue<long long,vector<long long>,greater<long long>>q;while(n--){int x;cin>>x;q.push(x);}long long answer=0;while(q.size()>1){long long x=q.top();q.pop();x+=q.top();q.pop();answer+=x;q.push(x);}cout<<answer<<"\n"; return 0; }
- 1
信息
- ID
- 4044
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者