#K38452. Maximum Consecutive Ones

    ID: 26201 Type: Default 1000ms 256MiB

Maximum Consecutive Ones

Maximum Consecutive Ones

You are given a binary array, i.e. an array that contains only 0s and 1s. Your task is to determine the maximum number of consecutive 1s in the array.

Formally, if the array is represented as \(a_1, a_2, \dots, a_n\), you need to find the maximum length \(\ell\) such that there exists an index \(i\) with \(a_i = a_{i+1} = \dots = a_{i+\ell-1} = 1\). In mathematical terms, find $$ \ell = \max_{\substack{1 \leq i \leq n}} \{ k : a_i = a_{i+1} = \dots = a_{i+k-1} = 1 \}. $$

This problem tests your ability to iterate over arrays and maintain counters.

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer n which denotes the number of elements in the array.
  • The second line contains n space-separated integers. Each integer is either 0 or 1.

outputFormat

The output is a single integer printed to standard output (stdout) representing the maximum number of consecutive 1s found in the array.

## sample
5
1 1 1 1 1
5