Getting SIGTSTP error

question :
my code :
when I run this program with custom input, it gives correct result but when I run it without custom input then it gives runtime error (SIGTSTP). Please help me to fix this problem.

Don’t run it without input

1 Like

When you run the code without providing custom input, your code waits infinitely for the input to be provided, and hence it throws a runtime error. Otherwise, your code has no other flaws to throw a runtime error and gives a WA instead on submitting. (Just in case you are facing this problem with CodeChef IDE, you must know that CodeChef IDE does not run your code by default on the sample test cases like some other sites.)


then what should I do?

If you want to check the code is right or not then provide custom input and run. Then submit the problem.

1 Like


code is also not submitting, gives TLE

Then your code has some problem. Use different logic

You may see this

In given solution, sort() method is used which means time complexity is O(nlogn) but I am trying to do it in O(n).
I am surprised, why my code gives TLE. Since, 10^8 operation can be done in 1 sec and here n <= 10^5. In worst case, code will run 6(10^5) times, in which 4(10^5) is for input. It would be nice If u try to fix my code. I spent almost two days on this problem!

for(int i = 0; i < n; i++)
	    int Time;
	    int t1 = searchV(arr[i][0], V, x);
	    int t2 = searchW(arr[i][1], W, y);

Your time comp is O(n * x * y)

1 Like

Oh yeah, got it. thanks!

still I am getting wrong answer(partially correct answer)

Earlier I was using linear search, so coplexity was around O(n^2) but now I am using binary search followed by quick sort now getting O(nlogn) but still something went wrong. pls help me to find out

Use upper_bound and lower_bound. This will save your time

1 Like

This is the third time I have seen the exact same mistake. Check your input loops.
@sebastian I have used upper_bound but still code is partiall submitted. Totally frustrated now.
@everule1 didn’t get ur point, plz elaborate!

	int W[y];
	for(i = 0; i < x; i++){
	    scanf("%d", &W[i]);

Do you see a problem now?

ohhh! got it.

still partially correct

std::upper_bound returns an iterator in the range [first, last) and hence in your code, it never checks the last element of the V[] and W[]. Change upper_bound(V, V + x - 1, ...) to upper_bound(V, V + x, ...) and similarly for W. Hopefully it’ll work now. :slight_smile: