#K53187. Maximizing Consecutive Available Books

    ID: 29476 Type: Default 1000ms 256MiB

Maximizing Consecutive Available Books

Maximizing Consecutive Available Books

Given a sequence of books where an available book is represented by 0 and a borrowed book is represented by 1, your task is to identify the longest consecutive subarray of available books. You must output three integers: the length of this subarray, the starting index, and the ending index (using 0-based indexing). If no available book exists, output 0 0 0.

The input is provided via standard input and the output should be written to standard output.

Note: Use \(\LaTeX\) format for any mathematical formulas if needed. In this problem, the subarray information can be summarized as: if \(a_i\) denotes the availability (with \(a_i=0\) indicating available), find indices \(l\) and \(r\) such that \(\sum_{i=l}^{r} [a_i=0]\) is maximized. If there is no available book, then output \(0 \ 0 \ 0\).

inputFormat

The first line contains an integer \(n\), the number of books. The second line contains \(n\) space-separated integers, each of which is either 0 or 1. Here, 0 indicates an available book and 1 indicates a borrowed book.

outputFormat

Output three space-separated integers on a single line: the length of the longest consecutive subarray of available books, the starting index, and the ending index. If no available book exists, output 0 0 0.

## sample
10
1 0 1 1 0 1 0 0 1 1
2 6 7

</p>