#BS0000457. Đoạn con hai nửa (Dvoniz)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đ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 and an integer . Call a contiguous segment of even length () interesting when the sum of its first entries is at most and the sum of its remaining entries is also at most .
For each index from to , determine the maximum length of an interesting segment whose left endpoint is exactly . 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 .
Each of the following lines contains the integer for the corresponding position .
Output
Print lines. On line , print the greatest length of an interesting segment starting at , or zero if none exists.
Subtasks
- Subtask 1 (20 points): ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; .
- Subtask 3 (50 points): ; ; ; ; .
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 and . For each position, choose the largest even length satisfying both bounds.