1 条题解
-
1
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; bool w = false; char c = getchar(); while (~c && !isdigit(c)) w |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); if (w) x = -x; } template <typename T> void write(T x) { static int stk[24]; int top = 0; while (x) { stk[++ top] = x % 10; x /= 10; } while (top) putchar(stk[top --] + 48); putchar(' '); } const double eps = 1e-5; const int N = 1e5 + 2; double l = 1e9, r = -1e9, sum[N]; int n, t, a[N]; bool check(double f) { double mi = 1e9; for (int i = 1; i <= n; i ++) sum[i] = sum[i - 1] + a[i] - f; for (int i = t; i <= n; i ++) { mi = min(mi, sum[i - t]); if (sum[i] - mi >= 0) return true; } return false; } int main() { read(n), read(t); for (int i = 1; i <= n; i ++) read(a[i]), l = min(l, (double)a[i]), r = max(r, (double)a[i]); for (double mid = (l + r) / 2.0; fabs(r - l) > eps; mid = (l + r) / 2.0) check(mid) ? l = mid : r = mid; write((int)floor(r * 1000)); // 警示后人,精度误差,只能写r return 0; }
- 1
信息
- ID
- 546
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- (无)
- 递交数
- 126
- 已通过
- 17
- 上传者