Codechef February lunchtime. Help needed.Getting SIGTSTP. New to CP

See the question here.

my approach is consider the array element that is less then or equal to n-count. will stop at the element that is greater then n-count. here is my code .

my Solution : CodeChef: Practical coding for everyone
SIGTSTP means a runtime error, so something like an infinite loop, which is exactly what you had.
in this bit of your code :

while(count<n)
{
if(ar[i]<=(n-count))
{
count+=ar[i];
i–;
idx–;
}
else{
break;
}
you had forgotten to put a break condition, essentially making it an infinite loop unless count == n, which was not the case in the 2nd test sample. A simple dry run on the sample test case would have given you the problem, so thats usually a good practice.
Happy Coding :slight_smile:
1 Like

Thanks man. That’s a logical error.

1 Like