Activity Selection Problems

#include
#include
#include
using namespace std;
int main() {
int t;
cin>>t;

while(t--)
{
   vector<pair<int,int>> v;
   int n,count=1;
   cin>>n;
   for(int i=0;i<n;i++)
   {
	  int x,y;
	  cin>>x>>y;
	  v.push_back(make_pair(x,y));
    }
    sort(v.begin(),v.end());

	for(int i=0;i<n;i++)
	  for(int j=i+1;j<n;j++)
	  {
		  if(v[i].second==v[j].first)
		  {
              count++;
		  }
	  }
 
    cout<<count;

}
return 0;

}

i’m getting wrong answer in test cases but manual input works properly .

@Pramod123 You have to make a bool comparison function and sure the values on increasing order of their ending times. Then Make any other operation.

sir my sort function is working properly without defining compare function separately … plz check my code for other issues.

@Pramod123 You have to sort the values according to the ending time of the activities then only you will be able to solve this problem.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like