-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path676C.cpp
More file actions
91 lines (78 loc) · 797 Bytes
/
Copy path676C.cpp
File metadata and controls
91 lines (78 loc) · 797 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
string s;
cin>>s;
int maxlen=0;
int st=0;
int ed=0;
int t=k;
//for a;
string s2=s;
while(ed<n && st<n)
{
if(s[ed]=='a')
{
maxlen=max(maxlen,ed-st+1);
ed++;
}
else
{
if(t>0)
{
ed++;
t--;
}
else
{
if(s[st]!='a')
{
st++;
t++;
}
else
{
st++;
}
}
}
}
st=0;
ed=0;
t=k;
while(ed<n && st<n)
{
if(s[ed]=='b')
{
maxlen=max(maxlen,ed-st+1);
ed++;
}
else
{
if(t>0)
{
ed++;
t--;
}
else
{
if(s[st]!='b')
{
st++;
t++;
}
else
{
st++;
}
}
}
maxlen=max(maxlen,ed-st);
//cout<<ed<<" "<<st<<endl;
}
cout<<maxlen<<endl;
return 0;
}