10分求助

P1090 [NOIP2004 提高组] 合并果子 / [USACO06NOV] Fence Repair G

@[haungyuze114514](/user/1060751) priority_queue不香吗? ```cpp #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { priority_queue<int,vector<int>,greater<int>> pq; ll n,x,ans=0; cin>>n; for(ll i=1;i<=n;i++) cin>>x,pq.push(x); while(pq.size()>=2) { ans+=pq.top(); int y=pq.top(); pq.pop(); ans+=pq.top(); y+=pq.top(); pq.pop(); pq.push(y); } cout<<ans; return 0; } ```
by wanjiayang @ 2023-11-01 16:32:11


|