starboy_99's blog

By starboy_99, history, 5 years ago, In English

Hello everyone, I am solving this problem but i am getting teminate:: bad alloc() error..anyone please tell me the error Here is my code;-

include<bits/stdc++.h>

using namespace std; bool sortinrev(const pair<int,int> &a,const pair<int,int> &b) { return (a.first > b.first);

}

int main() { int t; cin>>t; while(t--) { int n; cin>>n; vector<pair<int,int> > v;

for(int i=0;i<n;i++)
{
  int w,h;
  cin>>w>>h;
  v.push_back({w,h});
}

sort(v.begin(),v.end(),sortinrev);
vector<pair<int, int> > final;
final.push_back({v[0].first,v[0].second});
for(int i=1;i<v.size();i++)
{
  for(int j=0;j<final.size();j++)
  {
      if(v[i].first<final[j].first && v[i].second<final[j].second)
      {
        final[j].first=v[i].first;
        final[j].second=v[i].second;
      }
      else
      {
        final.push_back({v[i].first,v[i].second});
      }
  }

}
cout<<final.size()<<endl;

}

}

  • Vote: I like it
  • -8
  • Vote: I do not like it