#P8049. [COCI 2010/2011 #5] DVONIZ(加强版)

[COCI 2010/2011 #5] DVONIZ(加强版)

Background

The statement is the same as the original problem P7635 [COCI2010-2011#5] DVONIZ, except that the Constraints, time and memory limits, and score are different.

Problem Description

We call a sequence of 2×K2\times K elements interesting if the sum of the first KK elements or the sum of the last KK elements is not greater than SS.

Given a sequence AA of length NN, for each position, output the length of the longest interesting subarray starting from that position.

Input Format

The first line contains integers NN and SS.

Each of the next NN lines contains one integer AiA_i from the sequence AA. All these integers are positive, and their sum does not exceed 2×1092\times 10^9.

Output Format

Output NN lines in total. The ii-th line contains an integer representing the length of the longest interesting subarray starting from the ii-th element.

If there is no interesting subarray starting at this position, output 0.

5 10000
1
1
1
1
1 
4
4
2
2
0 
5 9
1
1
10
1
9 
2
0
0
2
0 
8 3
1
1
1
1
1
1
1
1 
6
6
6
4
4
2
2
0 

Hint

Sample Explanation #1

For the first position in Sample 11, there are 44 subarrays, and all of them satisfy the condition, so we take the longest one with length 44.

Constraints

For 30%30\% of the testdata, 2N2002\le N \le 200.

For 50%50\% of the testdata, 2N5×1032\le N \le 5 \times 10^3.

For 70%70\% of the testdata, 2N2×1052 \le N \le 2 \times 10^5.

For 100%100\% of the testdata, 2N3×1062\le N \le 3 \times 10^6, 1S1091\le S \le 10^9, 1Ai1091\le A_i \le 10^9.

Translated by ChatGPT 5