Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define ull unsigned long long
- #define pi 3.141592654
- #define NUM 1e18
- #define Mod 1'000'000'007
- #define fixed(n) fixed<<setprecision(n)
- #define cin(v) for(auto &i:v) cin >> i ;
- #define cout(v) for(auto &i:v) cout << i <<" ";
- #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
- #define small(x) (x>=97&&x<=122)
- #define capital(x) (x>=65&&x<=90)
- #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
- #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
- #define sz(x) (int)(x.size())
- #define all(v) ((v).begin()), ((v).end())
- #define allr(v) ((v).rbegin()), ((v).rend())
- #define updmax(a,b) a=max(a,b)
- #define updmin(a,b) a=min(a,b)
- #define ceil(a,b) ((a/b)+(a%b?1:0))
- /* asc -> 1 2 3 ,des -> 3 2 1 */
- /***********************************************************************************/
- using namespace std;
- void Rofyda_Elghadban(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- }
- void solve(){
- int n,k,maxi1=INT_MIN,counter1=0,maxi2=INT_MIN,counter2=0;
- cin>>n>>k;
- string s;
- cin>>s;
- string t=s;
- int temp1=k,temp2=k;
- char c1,c2;
- /*G*/
- for(int i=0;i<n;i++){
- temp1=k;
- if(s[i]!='G'){
- temp1--;
- counter1++;
- c1=s[i];
- }
- if(i<n-1){
- for(int j=i+1;j<n;i++){
- if(s[j]!=c1){
- counter1++;
- c1=s[j];
- }else{
- if(temp1>0){
- temp1--;
- counter1++;
- if(c1=='G'){
- s[j]=='B';
- }else{
- s[j]=='G';
- }
- }else{
- break;
- }
- }
- }
- }
- maxi1=max(maxi1,counter1);
- counter1=0;
- }
- /*B*/
- for(int i=0;i<n;i++){
- temp2=k;
- if(t[i]!='B'){
- temp2--;
- counter2++;
- c2=t[i];
- }
- if(i<n-1){
- for(int j=i+1;j<n;i++){
- if(t[j]!=c2){
- counter2++;
- c2=t[j];
- }else{
- if(temp2>0){
- temp2--;
- counter2++;
- if(c2=='B'){
- t[j]=='G';
- }else{
- t[j]=='B';
- }
- }else{
- break;
- }
- }
- }
- }
- maxi2=max(maxi2,counter2);
- counter2=0;
- }
- cout<<max(maxi1,maxi2)<<"\n";
- }
- int main(){
- Rofyda_Elghadban();
- int t=1;
- // cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement