Help me in solving ADVITIYA4 problem

My issue

time limit exceeded

My code

#include <bits/stdc++.h>
using namespace std;
#define ll long long


int main() {
	// your code goes here
	ll int t;
	cin>>t;
	while(t--)
	{
	    string s;
	    long long int n,q;
	    cin>>n>>q;
	    cin>>s;
	    ll int l=s.size();
	    vector<int> v;
	    int count=1;
	    for(int i=0;i<l;i++)
	    {
	        if(s[i]==s[i+1])
	        count++;
	        else
	        {
	        v.push_back(count);
	        count=1;
	        }
	    }
	    cout<<*max_element(v.begin(),v.end())<<" ";
	    for(int i=0;i<q;i++)
	    {
	        string s2;
	        cin>>s2;
	        if(s[s.size()-1]==s2[0])
	        {
	            v[v.size()-1]++;
	            s.append(s2);
	        }
	        else
	        {
	            v.push_back(count);
	            s.append(s2);
	        }
	        cout<<*max_element(v.begin(),v.end())<<" ";
	    }
	    
	    cout<<endl;
	   
	}
}

Problem Link: Another Good String Practice Coding Problem - CodeChef

@anon65274216
heyy plzz refer my c++ code for better understanding

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n,q;
	    cin>>n>>q;
	    string s;
	    cin>>s;
	    int ans=1,cnt=1;
	    for(int i=1;i<n;i++)
	    {
	        if(s[i]==s[i-1])
	        {
	            cnt++;
	        }
	        else
	        {
	            cnt=1;
	        }
	        ans=max(ans,cnt);
	    }
	    cout<<ans<<" ";
	    while(q--)
	    {
	        char ch;
	        cin>>ch;
	        s.push_back(ch);
	        if(s[s.size()-1]==s[s.size()-2])
	        cnt++;
	        else
	        cnt=1;
	        ans=max(ans,cnt);
	        cout<<ans<<" ";
	    }
	    cout<<endl;
	}

}