首页 > 代码库 > BZOJ 1724 切割木板

BZOJ 1724 切割木板

合并果子。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#define maxn 50050using 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\n",ans);    return 0;}

 

BZOJ 1724 切割木板