首页 > 其他 > 详细

【NOI2015】荷马史诗

时间:2019-08-29 00:46:23      阅读:88      评论:0      收藏:0      [点我收藏+]

题面

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;
}

 

【NOI2015】荷马史诗

原文:https://www.cnblogs.com/shxnb666/p/11427232.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!