TLE on pts#11 - pts#19
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long;
constexpr int maxn = 3e6+4;
int n, s;
int a[maxn];
int ans[maxn];
inline int read (void)
{
register int x = 0;
register char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ '0'),c = getchar();
return x;
}
signed main (void)
{
cin >> n >> s;
for (int i = 1; i <= n; i++)
{
a[i] = read();
a[i] += a[i - 1];
if (a[i] > 2e9) while (1);
}
for (int i = n; i; i--)
/* enumerate [mid] */
{
/* p[l - 1] >= p[mid] - s */
int l = lower_bound (a, a + n + 1, (ll) a[i] - s) - a + 1;
/* p[r] <= p[mid] + s */
int r = upper_bound (a, a + n + 1, (ll) a[i] + s) - a - 1;
int R = min (i - l + 1, r - i);
for (int j = i - R + 1; j <= i && !ans[j]; j++) ans[j] = (i - j + 1) << 1;
}
for (int i = 1; i <= n; i++) printf ("%d\n", ans[i]);
return 0;
}