Activity Selection Problem

have 2 doubts

1.why this code(have seen in other codes as well when I run them without an input) shows segmentation fault when i run it without an input

2.this solution is only passing 1 test case out of 2,what 's the problem in this code

1.That thing happens because you have written in your code to wait for input ie.cin>>n and you don’t provide it.So it shows segementation fault as your code is not ending itself as it is supposed to wait till you provide input and you don’t provide the input.
2.You are not printing the output in the right format.Like if there are two test cases then you should print it in:
1
2
but you are printing it as:
1 2.
Just add endl where i have mentioned as comment.