-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSCHEDULE.cpp
More file actions
executable file
·83 lines (79 loc) · 1.72 KB
/
SCHEDULE.cpp
File metadata and controls
executable file
·83 lines (79 loc) · 1.72 KB
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
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,k,cnt=1,j=0,maxi=0,sindex=0,eindex=0,i;
cin>>n>>k;
char s[n];
int a[n];
cin>>s;
while(k--)
{
for(i=1;i<n;i++)
{
if(s[i]==s[i-1])
cnt++;
else
{
//cout<<cnt<<endl;
if(cnt>maxi)
{
maxi=cnt;
sindex=i-cnt;
eindex=i-1;
}
cnt=1;
}
}
// cout<<cnt<<endl;
if(cnt>maxi)
{
maxi=cnt;
sindex=i-cnt;
eindex=i-1;
cnt=1;
}
if(maxi>1)
{
if(s[sindex]=='0')
s[(eindex+sindex)/2]='1';
else
s[(eindex+sindex)/2]='0';
eindex=-1;
sindex=-1;
}
maxi=0;
}
cnt=1;
for(i=1;i<n;i++)
{
//cout<<s[i]<<" ";
if(s[i]==s[i-1])
cnt++;
else
{
if(cnt>maxi)
{
maxi=cnt;
}
cnt=1;
}
}
if (cnt>maxi)
maxi=cnt;
// a[j]=cnt;
// j++;
// sort(a,a+j);
// if(flag&&j>k)
// cout<<max(a[j-k]/2,a[j-k-1])<<endl;
// else if(flag)
// cout<<a[j-k]/2<<endl;
// else
cout<<maxi<<endl;
}
}