Runtime error when using multiset


#1

solution: malloc.c:2374: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)’ failed.
Aborted
//code
vector Solution::slidingMaximum(const vector &a, int b) {

multiset<int> mp;
for(int i=0; i<b; i++) {
    mp.insert(a[i]);
}
vector<int> ret(a.size()-b+1);
for(int i=0;i<=ret.size(); i++) {
    // max element in set
    auto itr = mp.end();
    itr--;
    ret[i] = *itr;
    
    // removing element
    auto it = mp.find(a[i]);
    mp.erase(it);
    mp.insert(a[i+b]);
     
    
}
return ret;

}


#2

vector v;
multiset< int , greater > s;
for(int i=0;i<B;i++)
{
s.insert(A[i]);
}
auto j=s.begin();
v.push_back(*j);
for(int i=B;i<A.size();i++)
{
int va=i-B;
auto it=s.find(A[va]);
s.erase(it);
s.insert(A[i]);
auto m=s.begin();
v.push_back(*m);
}
return v;