PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000457. Đoạn con hai nửa (Dvoniz)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đoạn con hai nửa (Dvoniz)

Dvoniz

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of positive integers A1,A2,…,ANA_1,A_2,\ldots,A_N and an integer SS. Call a contiguous segment of even length 2K2K (K≥1K\ge1) interesting when the sum of its first KK entries is at most SS and the sum of its remaining KK entries is also at most SS.

For each index ii from 11 to NN, determine the maximum length of an interesting segment whose left endpoint is exactly ii. The segment must stay within the array and include all entries between its endpoints. Return zero for that index if no such segment exists.

Input

The first line contains integers N,SN,S.

Each of the following NN lines contains the integer AiA_i for the corresponding position ii.

Output

Print NN lines. On line ii, print the greatest length of an interesting segment starting at ii, or zero if none exists.

Subtasks

  • Subtask 1 (20 points): 2≤N≤1002\le N\le 100; 1≤S≤2⋅1091\le S\le2\cdot10^9; 1≤i≤N1\le i\le N; 1≤Ai≤2⋅1091\le A_i\le2\cdot10^9; ∑i=1NAi≤2⋅109\sum_{i=1}^N A_i\le2\cdot10^9.
  • Subtask 2 (30 points): 2≤N≤50002\le N\le 5000; 1≤S≤2⋅1091\le S\le2\cdot10^9; 1≤i≤N1\le i\le N; 1≤Ai≤2⋅1091\le A_i\le2\cdot10^9; ∑i=1NAi≤2⋅109\sum_{i=1}^N A_i\le2\cdot10^9.
  • Subtask 3 (50 points): 2≤N≤1000002\le N\le 100000; 1≤S≤2⋅1091\le S\le2\cdot10^9; 1≤i≤N1\le i\le N; 1≤Ai≤2⋅1091\le A_i\le2\cdot10^9; ∑i=1NAi≤2⋅109\sum_{i=1}^N A_i\le2\cdot10^9.

Examples

Input 1

5 10000
1
1
1
1
1

Output 1

4
4
2
2
0

Explanation 1

Every possible half meets the bound, so the largest even remaining lengths are 4, 4, 2, 2, 0.

Input 2

5 9
1
1
10
1
9

Output 2

2
0
0
2
0

Explanation 2

At index 1, (1,1) is valid, but the length-four segment has 10 in its second half. Every even segment beginning at index 2 or 3 includes 10. The segment (1,9) at index 4 is valid; the final index cannot start a pair.

Input 3

8 3
1
1
1
1
1
1
1
1

Output 3

6
6
6
4
4
2
2
0

Explanation 3

Each half may contain at most three ones. Thus K≤3K\le3 and 2K≤N−i+12K\le N-i+1. For each position, choose the largest even length satisfying both bounds.