forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1141B - Maximal Continuous Rest.cpp
131 lines (92 loc) · 2.42 KB
/
1141B - Maximal Continuous Rest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Each day in Berland consists of n hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence a1,a2,…,an (each ai is either 0 or 1), where ai=0 if Polycarp works during the i-th hour of the day and ai=1 if Polycarp rests during the i-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.
Input
The first line contains n (1=n=2·105) — number of hours per day.
The second line contains n integer numbers a1,a2,…,an (0=ai=1), where ai=0 if the i-th hour in a day is working and ai=1 if the i-th hour is resting. It is guaranteed that ai=0 for at least one i.
Output
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.
Examples
inputCopy
5
1 0 1 0 1
outputCopy
2
inputCopy
6
0 1 0 1 1 0
outputCopy
2
inputCopy
7
1 0 1 1 1 0 1
outputCopy
3
inputCopy
3
0 0 0
outputCopy
0
Note
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 4-th to the 5-th hour.
In the third example, Polycarp has maximal rest from the 3-rd to the 5-th hour.
In the fourth example, Polycarp has no rest at all.
*/
/*
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector <int> v(2 * n);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
v[i] = a;
}
for (int i = n; i < 2 * n; i++) v[i] = v[i - n];
int i = 0, res = 0, cnt = 0;
while (i < 2 * n) {
if (v[i] == 1) {
cnt++;
res = max(res, cnt);
} else cnt = 0;
i++;
}
cout << res << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
*/
#include<bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector <int> v(n);
for (auto &x: v) cin >> x;
int i = 0, res = 0, cnt = 0;
for (int i = 0; i < 2 * n; i++) {
if (v[i % n] == 1) {
cnt++;
res = max(res, cnt);
} else cnt = 0;
}
cout << res << "\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}