合并果子。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #define maxn 50050 using namespace std; long long n,x,ans=0; priority_queue <long long,vector<long long>,greater<long long> > q; int main() { scanf("%lld",&n); for (long long i=1;i<=n;i++) { scanf("%lld",&x); q.push(x); } while (q.size()!=1) { long long a=q.top();q.pop(); long long b=q.top();q.pop(); ans+=a+b;q.push(a+b); } printf("%lld ",ans); return 0; }