-
Notifications
You must be signed in to change notification settings - Fork 0
/
codechef - appy loves one.cpp
84 lines (74 loc) · 1.11 KB
/
codechef - appy loves one.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
#include<bits/stdc++.h>
using namespace std;
const int sz = 100010;
int arr[sz];
int lim;
int dummy;
int k, n, q;
int rightShift;
string query;
//void rightShift()
//{
// dummy = arr[n-1];
// for(int i=n-1; i>0; i--)
// {
// arr[i] = arr[i-1];
// }
// arr[0] = dummy;
//}
void lcs()
{
int cnt = 0;
int ans = -1;
int start;
if(rightShift%n==0)
{
start = 0;
}
else
{
start = n - (rightShift%n);
}
int i=start;
do
{
if(arr[i]==1)
{
cnt++;
}
else
{
cnt = 0;
}
ans = max(ans, cnt);
i = (i+1)%n;
} while(i!=start);
if(ans > k)
{
ans = k;
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> q >> k;
for(int i=0; i<n; i++)
{
cin >> arr[i];
}
cin >> query;
for(int i=0; i<q; i++)
{
if(query[i] == '!')
{
rightShift++;
}
else
{
lcs();
}
}
return 0;
}