Carvans Codechef Practice - Code Showing Runtime Error SIGTSTP

the link to the problem is here : https://www.codechef.com/problems/CARVANS

The following is my code and I am unable to find what is causing the SIGTSTP error -

#include<bits/stdc++.h>
#include<iostream>

using namespace std;

int main()
{
    int t;
    //cout<<"\nEnter the number of testcases:";
    scanf("%d", &t);

    while(t)
    {
        int n;
        //cout<<"\nEnter the number of cars";
        scanf("%d", &n);
        
        int s[n];
        for(int i=0;i<n;i++)
        {   
            //cout<<"\nEnter the speed ";
            scanf("%d", &s[i]);
        }

        int count = 0;
        
        if(n>1)
        {
            for(int l=0;(l+1)<n;l++)
            {
                if(l==0)
                    count++;
                if(s[l] > s[l+1])
                    count++;
                else
                    ;
            }
        }
        else
        {
            count++;
        }
        
        printf("%d",count);
        t--;
    }
    return 0;
}

N can be upto 10000. when N = 10000, s[n] will not work inside main function instead declare it globally with MAX value such as s[10000]. in problem it is said that use faster I/O so please go through the below article https://www.geeksforgeeks.org/fast-io-for-competitive-programming/

1 Like