Runtime Error in HORSES

I did it the right way. It showed run time error. Then i tried copy pasting a successfull submission which was same as mine, but then also it shows error. Can anyone tell what is the problem. Its the horses problem in easy section.

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here

int t;
cin>>t;
while(t--)
{
    long int h,i;
    cin>>h;
    long int arr[h];
    for(i=0;i<h;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+h);
    long int x=arr[1]-arr[0];
    for(i=2;i<h;i++)
    {
        if(arr[1]-arr[i-1]<x)
        {
            x=arr[1]-arr[i-1];
        }
    }
    cout<<x<<endl;
}
return 0;

}

‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’

Are you trying to “Run” without Providing “Custom Input”?

1 Like

I tried both with and without input. But it is showing same. runtime error- sigemt

Question link?
And also just put ``` above an below your code so I can see it properly on forum.

You are decrementing the t, but t is uninitialized. Additionally, none of the variables are initialized and hence it will throw exception everywhere.

int t = 100; //example
while(t–) {

}

@suhas199 but i already took T as input then i decremenred it.

I’m only getting Sigemt when I run it on empty input. You need to click the custom input button and put in the testcase, and then press run.

Secondly there’s a mistake here

if(arr[1]-arr[i-1]<x)
        {
            x=arr[1]-arr[i-1];
        }

I think you meant to type i, not 1.

Yes, it is ‘i’ in my code i just checked. Dont know how it is replaced by 1 here. I first pasted the code in MS word maybe there it got edited. And i just checked it runs succesfully with custom input. But why it is showing sigemt on empty? Will it be successfully submited? I did not submit it yet.

Thank you so much mam. I submitted it successfully. I was wasting time on this question for 2 hours. Mam, can you share your linkedin profile if you dont mind. I recently started on codechef and i have some queries as how to proceed further. U r a 5*, can be really helpful.

I’m in 11th, I don’t have a linkedin profile.

OK so, any tips in coding on codechef. How to ace and please tell something about contests. How, what and when should i start it . since i started codechef 2 days ago and currently did some easy practice problems only.