CF1141B.Maximal Continuous Rest

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Each day in Berland consists of nn hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a1,a2,,ana_1, a_2, \dots, a_n (each aia_i is either 00 or 11 ), where ai=0a_i=0 if Polycarp works during the ii -th hour of the day and ai=1a_i=1 if Polycarp rests during the ii -th hour of the day.

Days go one after another endlessly and Polycarp uses the same schedule for each day.

What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.

输入格式

The first line contains nn ( 1n21051 \le n \le 2\cdot10^5 ) — number of hours per day.

The second line contains nn integer numbers a1,a2,,ana_1, a_2, \dots, a_n ( 0ai10 \le a_i \le 1 ), where ai=0a_i=0 if the ii -th hour in a day is working and ai=1a_i=1 if the ii -th hour is resting. It is guaranteed that ai=0a_i=0 for at least one ii .

输出格式

Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.

输入输出样例

  • 输入#1

    5
    1 0 1 0 1
    

    输出#1

    2
    
  • 输入#2

    6
    0 1 0 1 1 0
    

    输出#2

    2
    
  • 输入#3

    7
    1 0 1 1 1 0 1
    

    输出#3

    3
    
  • 输入#4

    3
    0 0 0
    

    输出#4

    0
    

说明/提示

In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.

In the second example, Polycarp has maximal rest from the 44 -th to the 55 -th hour.

In the third example, Polycarp has maximal rest from the 33 -rd to the 55 -th hour.

In the fourth example, Polycarp has no rest at all.

首页