/bin/run.sh: line 4: 18 Segmentation fault (core dumped) ./exe
i am getting this tye of error
Activity selection
#include
#include<bits/stdc++.h>
using namespace std;
struct Activity{
int startTime;
int finishTime;
};
bool compare(Activity a1,Activity a2){
return a1.finishTime < a2.finishTime;
}
int main(){
int t;
cin>>t;
while(t–){
int n;
cin>>n;
Activity activity[n];
for(int i=0;i<n;i++){
cin>>activity[i].startTime>>activity[i].finishTime;
}
sort(activity,activity+n,compare);
int count = 1;
int i = 0;
for(int j=1;j<n;j++){
if(activity[j].startTime >= activity[i].finishTime){
count++;
i = j;
}
}
cout<<count<<endl;
return 0;
}
}
i used t then also one test case is getting failed…please provide the solution
can i send through mail
i cant understand how to share the code through coding blocks ide
@karthik1989photos
go to ide.codingblocks.com
paste your code in the editor
save
share the link generated here
when i saved and after sharing it is saving in server and also when i am directly clicking share option in codingblocks ide it is mail id
asking mailid when i clicked on share option
@karthik1989photos just copy paste the link that is generated. click on save, then copy the url of the code and paste it here
Here is my code. Find it at Coding Blocks IDE.
@karthik1989photos please share the link. You can use any other online editor also if you are not getting how to share via the CB IDE
hi @karthik1989photos
your return 0; statement is inside the while loop, so your program will terminate after the first test case thus giving wrong answer.
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.