#include <bits/stdc++.h> #define int long long //(有超时风险) #define PII pair<int,int> #define endl '\n' #define LL __int128 using namespace std; const int N=2e6+10,M=1e3+10,mod=998244353,INF=0x3f3f3f3f; int a[N],b[N],c[N],pre[N]; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n;cin>>n; priority_queue<int,vector<int>,greater<int>>q; for(int i=1;i<=n;i++) cin>>a[i],q.push(a[i]); int ans=0; while(q.size()>1) { int a=q.top();q.pop(); int b=q.top();q.pop(); ans+=a+b; q.push(a+b); } cout<<ans<<endl; return 0; }
P1090 [NOIP2004 提高组] 合并果子--优先队列
最新推荐文章于 2024-05-20 15:29:54 发布