CF1141B.Maximal Continuous Rest

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

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.

伯兰的每一天由 nn 个小时组成。波利卡普喜欢时间管理,因此他每天都有一个固定的时间表——即一个序列 a1,a2,…,ana_1, a_2, \dots, a_n(其中每个 aia_i 为 00 或 11):若 ai=0a_i = 0,表示波利卡普在当天第 ii 个小时工作;若 ai=1a_i = 1,表示他在当天第 ii 个小时休息。

日子无限循环往复,而波利卡普每天都使用相同的时间表。

波利卡普连续休息的最大小时数是多少?题目保证每天至少存在一个小时用于工作。

输入格式

The first line contains nn (1≤n≤2⋅1051 \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 (0≤ai≤10 \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.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2\cdot10^5),表示一天中的小时数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤10 \le a_i \le 1),其中若第 ii 小时为工作时间,则 ai=0a_i = 0;若第 ii 小时为休息时间,则 ai=1a_i = 1。保证至少存在一个 ii 满足 ai=0a_i = 0。

输出格式

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.

输出 Polycarp 连续休息的最大小时数。注意,需考虑天数无限循环,且 Polycarp 每天都使用相同的作息安排。

输入输出样例

  • 输入#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.

在第一个例子中,最长的休息时段从最后一小时开始,持续到第二天的第一小时。

在第二个例子中,Polycarp 的最长休息时段是从第 44 小时到第 55 小时。

在第三个例子中,Polycarp 的最长休息时段是从第 33 小时到第 55 小时。

在第四个例子中,Polycarp 完全没有休息。

输入解题思路,AI测评打分。不知道怎么写?

首页