Why my code is not accepted? (HORSES)

#include
using namespace std;

int main() {
int t,i,j,min;
int m,n,temp;

cin>>t;

for(m=1;m<=t;m++)
{ cin>>n;

int s[n];

for(i=0;i<n;i++)
    cin>>s[i];
    
for(i=0;i<n;i++)

{ min=i;
for(j=i+1;j<n;j++)
if(s[j]<s[min])
min=j;

   temp=s[i];
   s[i]=s[min];
   s[min]=temp;

}

 int c[n-1];
   temp=s[0];
 
   for(i=0;i<n;i++)
     c[i]=s[i+1]-s[i];
    
    temp=c[0];
    for(i=0;i<n-1;i++)
    {
        if(temp>c[i])
        temp=c[i];
    }
    
    cout<<temp;

}
// your code goes here
return 0;
}

Which problem you are trying to solve?

2 Likes

Racing Horses.

So your problem link is: https://www.codechef.com/problems/HORSES
And your last submission:https://www.codechef.com/viewsolution/30731065

1 Like

yes

After printing your answer, you are not going to the next line.

Instead of
cout << temp;

You do,

cout << temp << endl;

Found the wrong.
For this input:

2
5
4 12 17 22 32
4
4 7 9 16

Your Output:
52
Only 52
But it should be:

5
2

It is the correct output. but your output is wrong. so your code is not printing correct output. So, wrong is in your last line.

1 Like

Many thanks, :smile:
Its working now

2 Likes

Thanks, I got it :slight_smile: