Something wrong with Activity Selection Code , Gives Seg fault

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(n) for (ll i=0;i<n;i++)
#define test ll t;cin>>t;while(t–)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#include
#include
#include
#include
#include
bool comparator (pair<int , int > a , pair<int, int > b) {
if ( a.second <= b.second) {
return true ;
}
return false ;
}
void solve()
{
int N ;
// No of activities
cin >> N ;
pair<int , int> arr[N];

for ( int i = 0 ; i < N ; i++) {
	int x1, x2;
	cin >> x1 >> x2;
	arr[i] = make_pair(x1, x2);
}

sort (arr, arr + N, comparator);

for (int i = 0 ; i < N; i++) {
	cout << arr[i].first << " " << arr[i].second << endl;
}
int count = 0, currentEnd = 0;
for (int i = 0; i < N ; i++) {
	if (currentEnd > arr[i].first) {
		continue;
	}
	else {
		count++;
		currentEnd = arr[i].second;
	}
}
cout << count;

}
int main()
{
// fast
// #ifndef ONLINE_JUDGE
// freopen(“input.txt”, “r”, stdin);
// freopen(“output.txt” , “w” , stdout);
// #endif

ll t ;
cin >> t ;
while (t--) {
	solve();
}

}

hello @achin1tya
pls share ur code using cb ide.

@achin1tya
check now->

1 Like

yup this works in IDE but on system it gives seg fault , hmm I guess something might be wrong with the way I was running it .

@achin1tya
your code is correct.

yeah it might be thr reason

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.