Bad_alloc error


#1

Why i am getting bad_alloc error please anyone tell me
indent preformatted text by 4 spaces
vector Solution::equal(vector &A) {
vector<pair<int,int> > arr;
vector ans;
if(A.size() < 4)
return ans;
for(int i = 0;i < A.size();i++)
{
arr.push_back(make_pair(A[i],i));
}
sort(arr.begin(),arr.end());
set<vector > s;
for(int i = 0;i < arr.size()-3;i++)
{
for(int j = i+1;j < arr.size()-2;j++)
{
int sum = arr[i].first+arr[j].first;
int l = j+1,h = arr.size()-1;
while(l < h)
{
if(arr[l].first + arr[h].first < sum)
l++;
else if(arr[l].first + arr[h].first > sum)
h–;
else
{
vector v;
v.push_back(arr[i].second);
v.push_back(arr[j].second);
v.push_back(arr[l].second);
v.push_back(arr[h].second);
s.insert(v);
l++;
h–;
}

        }
    }
}
auto it = s.begin();
ans = *it;
return ans;

}