考虑说我们每一次要么把前面最开始的一次给放了,要么接完了混合起来放
考虑维护一个温度单增的单调队列
每一次把最开始的弹出就是了
考虑最后一个加进来
如果不单调就一定是混合起来放
合并一下就完了
#include<bits/stdc++.h>
using namespace std;
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define re register
#define pb push_back
#define cs const
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
cs int mod=1e9+7;
inline int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline void Add(int &a,int b){(a+=b)>=mod?(a-=mod):0;}
inline int dec(int a,int b){return (a-=b)<0?a+mod:a;}
inline void Dec(int &a,int b){(a-=b)<0?(a+=mod):0;}
inline int mul(int a,int b){return 1ll*a*b>=mod?1ll*a*b%mod:a*b;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline int ksm(int a,int b,int res=1){
for(;b;b>>=1,a=mul(a,a))(b&1)&&(res=mul(res,a));return res;
}
inline void chemx(ll &a,ll b){a<b?a=b:0;}
inline void chemn(int &a,int b){a>b?a=b:0;}
int n,L,l,r;
long double tmp,siz;
cs int N=500005;
struct node{
long double v,t;
}q[N];
int main(){
n=read(),L=read();
l=1;
for(int i=1;i<=n;i++){
node now;
now.t=read(),now.v=read();
while(l<=r&&siz+now.v>L){
long double del=min(q[l].v,siz+now.v-L);
q[l].v-=del,siz-=del,tmp-=del*q[l].t;
if(!q[l].v)l++;
}
siz+=now.v,tmp+=now.v*now.t;
printf("%.7Lf
",(1.0*tmp/L));
while(l<=r&&q[r].t>=now.t){
now.t=(now.v*now.t+q[r].t*q[r].v)/(q[r].v+now.v);
now.v+=q[r].v,r--;
}
q[++r]=now;
}
}