传送门

全世界都会二分可海星……

首先记\(sum[i]\)为\(a[i]\)的前缀和,那么第\(i\)个的答案就是\(max\{\frac{sum[i]-sum[j-1]}{x+(i-j)d}\}\),那么我们可以把式子给看做点\((j*d,sum[j-1])\)和\((x+i*d,sum[i])\)的斜率。发现前面那个是一个定值,于是我们可以维护一个下凸包,因为凸包上的斜率单调增,每一次在这个凸包上二分最大的斜率即可

//minamoto
#include<bits/stdc++.h>
#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
#define ll long long
#define eps 1e-3
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
ll read(){
ll res,f=1;char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
const int N=1e5+5;
int n,top,l,r,mid,ret;ll d,a[N],sum[N],x[N];double ans;
struct node{ll x,y;}st[N],res;
inline double slope(const node &a,const node &b){return 1.0*(b.y-a.y)/(b.x-a.x);}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),d=read();
fp(i,1,n)a[i]=read(),x[i]=read(),sum[i]=sum[i-1]+a[i];
fp(i,1,n){
res={d*i,sum[i-1]};
while(top&&slope(st[top-1],st[top])>slope(st[top],res))--top;
st[++top]=res,res={x[i]+d*i,sum[i]};
l=1,r=top;
while(l<=r){
mid=(l+r)>>1;
(slope(st[mid],res)>slope(st[mid-1],res))?l=mid+1,ret=mid:r=mid-1;
}ans+=slope(st[ret],res);
}printf("%.0lf\n",ans);return 0;
}

最新文章

  1. Linux C popen()函数详解
  2. Adapter 启动时报错——2
  3. FreeRadius服务器安装以及error while loading shared libraries问题
  4. RSA数字证书管理
  5. Redis集群的配置
  6. markdown 设置字体颜色
  7. android ViewGroup事件分发机制
  8. typdef struct 语法
  9. Activiti的Eclipse插件离线安装指南
  10. 【HTML】Beginner6:Link
  11. 持续集成之戏说Check-in Dance
  12. 类型萃取(type traits)
  13. hdu 4465 概率称号
  14. vue中的computed(计算属性)和watch(监听属性)的特点,以及深度监听
  15. UIdynamic系列认知
  16. 自动化测试-10.selenium的iframe与Frame
  17. 自动化部署shell
  18. shell 检测安装包
  19. Python+Django(Python Web项目初体验)
  20. Spark-Cache与Checkpoint

热门文章

  1. zip相关知识梳理(一)
  2. UVA - 1623 Enter The Dragon(贪心)
  3. Spark在Executor上的内存分配
  4. Error:java: Internal compiler error: java.lang.Exception: java.lang.NoClassDefFoundError解决
  5. HXY烧情侣(洛谷 2194)
  6. ORACLE分区表删除分区数据
  7. 51Nod——T 1631 小鲨鱼在51nod小学
  8. CH上的Think Bear#1模拟赛
  9. 深入解析Microsoft Sql server 2008
  10. CSS filter 模拟黑洞照片效果