题目
图解
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n, x;
int h[N];
bool check(int mid)
{for(int i = 1; i + mid - 1 < n; i++)if(h[i + mid - 1] - h[i - 1] < 2 * x) return false;return true;
}
int main()
{cin >> n >> x;for(int i = 1; i < n; i++)cin >> h[i], h[i] += h[i-1];int l = 1, r = n;while(l < r){int mid = l + r >> 1;if(check(mid)) r = mid;else l = mid + 1;}cout << l;
}