题面
https://www.luogu.org/problem/P2168
题解
#include<cstdio> #include<iostream> #include<queue> #define LL long long #define ri register int using namespace std; struct node{ LL x,v; bool operator < (const node &rhs) const { return x>rhs.x || x==rhs.x && v>rhs.v; } }; priority_queue<node> pq; int n,m; int main(){ LL x; scanf("%d %d",&n,&m); for (ri i=1;i<=n;i++) { scanf("%lld",&x); pq.push((node){x,0}); } while ((n-1)%(m-1)!=0) ++n,pq.push((node){0LL,0}); LL ans=0; while (pq.size()>1) { LL sum=0; LL d=0; for (ri i=1;i<=m;i++) if (!pq.empty()) { node now=pq.top(); pq.pop(); sum+=now.x; if (now.v>d) d=now.v; } ans+=sum; pq.push((node){sum,++d}); } cout<<ans<<endl<<pq.top().v<<endl; }