我太弱了,真的没有搞懂
yi=max{(sum[i]-sum[j-1])/(x[i]+(i-j)*d)} 1<=j<=i
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 100000 + 5;
ll x[N],sum[N],a[N],d;
int st[N],top,n;
double ans;
double xie(int i,int j){
double x = (double)d * i - (double)d * j; double y = sum[i-1] - sum[j-1];
return y/x;
}
double work(int i,int j){
double res = (double)( sum[i] - sum[j-1] ) / (double)( x[i] + d*i - d*j );
return res;
}
int main(){
scanf("%d%lld", &n, &d);
for( int i = 1; i <= n; i++ ){
scanf("%lld%lld", &a[i], &x[i]);
sum[i] = sum[i-1] + a[i];
}
for( int i = 1; i <= n; i++ ){
while( top > 1 && xie(i,st[top]) < xie(st[top],st[top-1])) top--;
st[++top] = i; int l = 1, r = top;
while( l != r ){
int len = (r-l+1)/3;
int x1 = l-1+len; int x2 = l-1+len*2;
if( x1 == x2 ) break;
if( work(i,st[x1]) < work(i,st[x2]) ) l = x1+1;
else r = x2-1;
}
ans += max( work(i,st[l]), work(i,st[r]) );
}
printf("%.0lf",ans);
return 0;
}