1 #include <iostream> 2 #include <algorithm> 3 using namespace std; 4 const int N = 1e5 + 5; 5 double sum[N], cows[N]; 6 int n, f; 7 8 bool check(double avg){ 9 for(int i = 1; i <= n; ++ i) sum[i] = sum[i-1] + cows[i] - avg;//求前缀和 10 double minv = 0; 11 for(int i = 0, j = f; j <= n; ++ j, ++ i){ 12 minv = min(sum[i], minv);//找出0-i之间的最小值 13 if(sum[j] >= minv) return true;//判断是否满足条件 14 } 15 return false; 16 } 17 18 int main(){ 19 cin >> n >> f; 20 for(int i = 1; i <= n; ++ i) cin >> cows[i]; 21 double l = 0, r = 2000; 22 while(r - l > 1e-5){//浮点数二分 23 double mid = (l+r)/2; 24 if(check(mid)) l = mid; 25 else r = mid; 26 } 27 cout << int(r * 1000) << endl;//向下取整 28 return 0; 29 }