百度网站建设工资,网络运营工程师,工业和信息化部网站备案管理系统,苏州网站制作及推广p题意#xff1a;给定一个序列#xff0c;然后从中选择两个数#xff0c;相加后放入原来的序列#xff0c;消耗的费用为两个数 的和#xff0c;问最小的代价。/pp/pp思路#xff1a;贪心。用优先队列维护#xff0c;每次取得时…
p题意给定一个序列然后从中选择两个数相加后放入原来的序列消耗的费用为两个数 的和问最小的代价。/pp
/pp思路贪心。用优先队列维护每次取得时候都取最小的两个即可。/pp
/ppcode/p
#include bits/stdc.h
using namespace std;int main()
{int n,x;while (~scanf(%d,n)n){priority_queueint,vectorint,greaterint q;for (int i0;in;i)scanf(%d,x),q.push(x);int ans0;for (int i0;in-1;i){int aq.top();q.pop();int bq.top();q.pop();ansab;q.push(ab);}printf(%d\n,ans);}
}