[第1章 1.4t8] 荷马史诗
52 字
1 分钟
[第1章 1.4t8] 荷马史诗
#include <bits/stdc++.h>#define endl '\n'using namespace std;typedef long long ll;typedef pair<ll,ll> pll;int main(){ ll n,k; cin>>n>>k; priority_queue<pll,vector<pll>,greater<>> pq; for(ll i=1;i<=n;i++){ ll w; cin>>w; pq.push({w,0}); } ll ans=0; ll ma=0; while((pq.size()-1)%(k-1)!=0)pq.push({0,0}); while(pq.size()>1){ ll tmp=0; ll h=0; for(ll i=0;i<k;i++){ tmp+=pq.top().first; h=max(h,pq.top().second); pq.pop(); } ans+=tmp; pq.push({tmp,h+1}); } cout<<ans<<endl<<pq.top().second<<endl; return 0;}支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!
相关文章智能推荐
1
[第2章 2.2e1] Palindromes
算法竞赛2026-06-27
2
[第2章 2.2t1] Subsequence
算法竞赛2026-06-27
3
[第1章 1.2t2] 扫描
算法竞赛2026-06-26
4
[第1章 1.5t4] 蚯蚓
算法竞赛2026-06-26
5
[第1章 1.1t1] 队列安排
算法竞赛2026-06-26
随机文章随机推荐





