-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chef and Sub Array.cpp
70 lines (50 loc) · 1.14 KB
/
Chef and Sub Array.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
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,k,p;
int i,j,temp,count_one,l,max_count,z,lm_f_bit,m;
temp=0;
cin>>n>>k>>p;
int bin[n];
char req[p];
for(i=0;i<n;i++)
cin>>bin[i];
cin>>req;
for(i=0;i<p;i++)
{
if(req[i]=='?')
{
count_one=max_count=z=0;
for(l=0;l<k;l++)
{
if(bin[l]==1)
count_one++;
}
lm_f_bit=bin[z++];
max_count=count_one;
for(m=l;m<n;m++)
{
if(bin[m]==1 && lm_f_bit==0)
count_one++;
if(bin[m]==0 && lm_f_bit==1)
count_one--;
lm_f_bit=bin[z++];
if(count_one>max_count)
max_count=count_one;
if(max_count==k)
break;
}
cout<<max_count<<"\n";
}
else
{
temp=bin[n-1];
for(j=n-1;j>0;j--)
bin[j]=bin[j-1];
bin[0]=temp;
}
}
return 0;
}