论文题。自行搜索《浅谈数形结合在信息学竞赛中的应用》
我的代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn = 100005;
LL n,m,a[maxn],s[maxn];
LL q[maxn],hd,tl;
LL getY(LL j,LL k){
return s[k] - s[j];
}
LL getX(LL j,LL k){
return k - j;
}
void solve(){
hd = tl = 0;
q[tl++] = 0;
LL ans = 0;
for(LL i=m;i<=n;i++){
while(hd+1<tl && getY(q[hd],q[hd+1])*getX(q[hd+1],i) <= getY(q[hd+1],i)*getX(q[hd],q[hd+1])) hd++;
ans = max(ans,1000*getY(q[hd],i)/getX(q[hd],i));
while(hd+1<tl && getY(q[tl-1],i-m+1)*getX(q[tl-2],q[tl-1]) <= getY(q[tl-2],q[tl-1])*getX(q[tl-1],i-m+1)) tl--;
q[tl++] = i-m+1;
}
printf("%I64d\n",ans);
}
int main(){
scanf("%I64d%I64d",&n,&m);
for(LL i=1;i<=n;i++){
scanf("%I64d",&a[i]);
s[i] = s[i-1] + a[i];
}
solve();
return 0;
}