Getting TLE in Good Prefix(PRFXGD)

I am getting TLE in PRFXGD .

#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define sevensins ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define mod 1000000007
#define vect vector
#define bins binary_search
#define vecti vector::iterator
#define bitout __builtin_popcount
#define binsrch binary_search
int main()
{sevensins
ll t,i,j,k,l,n,x;
cin>>t;
while(t–)
{
string s;
cin>>s;

cin>>k>>x;

ll count=0;

multiset<char> m;
set<char> c;

if(k==0)
{   
    for(i=0;i<s.size();i++)
    {
        m.insert(s[i]);
        
        if(m.count(s[i])<=x)
        {
            count++;
        }
        else
        break;
    }
    cout<<count<<"\n";
}

}
return 0;
}

This code is only for subtask-1.
can any one help please.

Maybe multiset takes the time not sure! use simple mapping you will get accepted :slightly_smiling_face:

This question can be done by done in linear time by iterating through given string and by maintaining a array of size 26 which will keep track of number of occurrence if each alphabet. I have given link to my code.
https://www.codechef.com/viewsolution/30827511

Yes I know but I just wanted to know why this method is getting TLE.

m.count() function doesnt work as it looks to you it takes O(n) time which is making your solution quadratic. i hope you got what i meant