I am trying to solve a hackerrank problem on "Fraudulent Notification". While I passes some of the test cases, i get time limit exception as my algorithm is not efficient enough. Note i am trying to do it in c++ and using std::multimap as element would be in sorted order and hence insertion, deletion etc. from data structure would be relatively fast. Link to the hackerank problem is : https://www.hackerrank.com/challenges/fraudulent-activity-notifications/problem. Moreover one of the test cases against which i get time limit exceeded is at the link https://hr-testcases-us-east-1.s3.amazonaws.com/26114/input01.txt?AWSAccessKeyId=AKIAR6O7GJNX5DNFO3PV&Expires=1681754385&Signature=O64%2FYgms0Psub8VZQQpvlGYHEiw%3D&response-content-type=text%2Fplain.
Note i did see some of the question like C++ Efficiently Calculating a Running Median in SO here, but my understanding to some of these order statistic tree and advanced template is very limited, so I thought if there is something else or a more easier and efficient approach to the problem. Thanks in advance.
int activityNotifications(vector<int> expenditure, int d) {
    int total_warning=0;
    //std::vector<double> median_arr;
    std::multiset<double> arr;
    int total_days=expenditure.size();
    for(int i=0;i<d;++i)
    {
        arr.insert(expenditure[i]);
    }
    for(int i=d,j=0;i<total_days;++i,++j)
    {
        double median;
        double a = *next(arr.begin(),d/2);
        double b = *next(arr.begin(),d/2 + 1);
        if(d & 1)
        {
            median=a;
            //median_arr.push_back(a);
            //std::cout <<"Median is b:" << median << endl;
        }
        else 
        {
            median=(double(a+b))/2;
            //median_arr.push_back((a+b)/2);
            //std::cout <<"Median is a+b :" << median << endl;
        }
        arr.insert(expenditure[i]);
        arr.erase(arr.find(expenditure[j]));
        //std::cout <<"Median * 2 :" << median*2 << endl;
        //std::cout <<"Expenditure :" << expenditure[i] << endl;
        if(expenditure[i] >= (median*2) )
        {
            ++total_warning;
        }
    }
    return total_warning;
}
 
     
    