题目:
思路:
答案的范围很容易确定,重要的是check()这一步
搞一个b[i]=100*a[i]-avg;
s[i]是b[i]的前缀和数组
AC代码:
#include<cstdio>
#include <iostream>
#include<cstring>
#include<algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
const int maxn=111111;
int minn=0x3f3f3f3f;
int n,m,a[maxn];
long long b[maxn],s[maxn],mi[maxn];
bool check(long long avg)
{
mi[0]=0;
for(int i=1;i<=n;i++) b[i]=1000*a[i]-avg;
for(int i=1;i<=n;i++) s[i]=s[i-1]+b[i];
for(int i=1;i<=n;i++) mi[i]=min(mi[i-1],s[i]);
//for(int i=1;i<=n;i++) cout<<"i="<<i<<" "<<b[i]<<" "<<s[i]<<" "<<mi[i]<<endl;
for(int i=m;i<=n;i++)
{
if(s[i]>=mi[i-m])
{
//cout<<"i="<<i<<" "<<"s[i]="<<s[i]<<
return 1;
}
}
return 0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
minn=min(a[i],minn);
}
long long l=minn,r=2e13;
while (l<r)
{
long long mid=(l+r+1)>>1;
//cout<<"mid="<<mid<<" "<<"check(mid)="<<check(mid)<<endl;
if(check(mid)) l=mid;
else r=mid-1;
//cout<<"l="<<l<<" "<<"r="<<r<<endl;
}
cout<<l<<endl;
return 0;
}