标签:bool enc sum scan 题意 algo define 子序列 can
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
//Mystery_Sky
//
#define M 10000100
#define ex 1e-5
double l = 100000.0, r = -10000.0, mid;
int n, L;
double a[M], sum[M];
inline bool check(double ans)
{
double sum1, sum2, maxx;
sum1 = sum[L-1] - (L-1) * ans;
for(int i = L; i <= n; i++) {
sum2 = sum[i] - sum[i - L] - L * ans;
sum1 = sum1 + a[i] - ans;
sum1 = max(sum1, sum2);
if(sum1 > -ex) return true;
}
return false;
}
int main() {
scanf("%d%d", &n, &L);
for(int i = 1; i <= n; i++) {
scanf("%lf", &a[i]);
sum[i] = sum[i-1] + a[i];
l = min(l, a[i]), r = max(r, a[i]);
}
while(r - l > ex) {
mid = (l + r)/2;
if(check(mid)) l = mid;
else r = mid;
}
int ans = (int)(r * 1000);
printf("%d", ans);
return 0;
}
标签:bool enc sum scan 题意 algo define 子序列 can
原文地址:https://www.cnblogs.com/Benjamin-cpp/p/10878188.html