这么裸的斜率优化,结果果断调试了两个多小时,长时间不复习真是脑残了……
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long f[100100];
int q[100100];
int main()
{
int n,F,a;
while(scanf("%d%d",&n,&F)==2)
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a);
f[i]=f[i-1]+a;
}
int l=0,r=0;
long long ans=0;
for(int i=F;i<=n;i++)
{
while(l+1<r&&(f[i-F]-f[q[r-1]])*(q[r-1]-q[r-2])<=(f[q[r-1]]-f[q[r-2]])*(i-F-q[r-1])) r--;
q[r++]=i-F;
while(l+1<r&&(f[i]-f[q[l+1]])*(i-q[l])>=(f[i]-f[q[l]])*(i-q[l+1])) l++;
ans=max(ans,(f[i]-f[q[l]])*1000/(i-q[l]));
}
printf("%lld\n",ans);
}
return 0;
}