样例过了,用的二分+单调队列check, chk 函数用来验证 mid 的值是否正确。
不是 freopen 的问题,本贴提到的所有提交结果均为去掉 freopen 后的提交结果。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n;
ll s, t;
ll a[100001];
double tmp[100001];
double sum[100001];
bool chk(double x)
{
for(int i = 1; i <= n; i++)
tmp[i] = a[i] - x, sum[i] = sum[i - 1] + tmp[i];
deque <ll> q;
for(int i = s; i <= n; i++)
{
while(q.size() && sum[q.back()] - sum[i - s] <= 1e-6)
q.pop_back();
q.push_back(i - s);
if(q.size() && i - q.front() > t)
q.pop_front();
if(q.size() && sum[i] - sum[q.front()] >= 0)
return 1;
}
return 0;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
freopen("P1419.in", "r", stdin);
cin >> n >> s >> t;
for(int i = 1; i <= n; i++)
cin >> a[i];
double l = -1e4, r = 1e4, ans;
while(r - l > 1e-6)
{
double mid = (l + r) / 2;
if(chk(mid))
l = mid + 0.00001, ans = mid;
else
r = mid - 0.00001;
}
cout << setprecision(3) << fixed << ans;
return 0;
}