合并果子
from acwing 148
时间限制:1s
空间限制:64MB
简单贪心。
AC代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define start ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int n,sum,x,y;
priority_queue<int,vector<int>,greater<int> > q;
signed main(){
cin>>n;
for(int i = 1;i <= n;++i)
cin>>sum,q.push(sum);
sum = 0,--n;
while(n--)
x = q.top(),q.pop(),y = q.top(),q.pop(),sum += x + y,q.push(x + y);
cout<<sum;
return 0;
}