CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • May Cook-Off 2013
    • May Challenge 2013
    • April Cook-Off 2013
    • April Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September Challenge 2012 » Racing Horses

Racing Horses

Problem code: HORSES

  • All Submissions

All submissions for this problem are available.

Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and so he wants the race to be close. This can happen only if the horses are comparable on their skill i.e. the difference in their skills is less.

There are N horses in the stable. The skill of the horse i is represented by an integer S[i]. The Chef needs to pick 2 horses for the race such that the difference in their skills is minimum. This way, he would be able to host a very interesting race. Your task is to help him do this and report the minimum difference that is possible between 2 horses in the race.

Input:

First line of the input file contains a single integer T, the number of test cases.
Every test case starts with a line containing the integer N.
The next line contains N space separated integers where the i-th integer is S[i].

Output:

For each test case, output a single line containing the minimum difference that is possible.

Constraints:

1 ≤ T ≤ 10
2 ≤ N ≤ 5000
1 ≤ S[i] ≤ 1000000000

Example:

Input:
1
5
4 9 1 32 13

Output:
3

Explanation: The minimum difference can be achieved if we pick horses with skills 1 and 4 for the race.

Author: vamsi_kavala
Tester: laycurse
Editorial http://discuss.codechef.com/problems/HORSES
Date Added: 2-07-2012
Time Limit: 3 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

what if two horses have same

vineetsetia @ 1 Sep 2012 03:44 PM
what if two horses have same skills?...

@vineetsetia We can choose

hiroto_adm @ 1 Sep 2012 03:58 PM
@vineetsetia We can choose two horses which have the same skills. Of course, in this case, the answer will be 0.

Well... The answer I

codersrikant @ 1 Sep 2012 04:03 PM
Well... The answer I submitted shows nothing.. neither TLE neither Runitme nothing.. just remsins in infinte loop. :(

OMG it now shows correct

codersrikant @ 1 Sep 2012 04:04 PM
OMG it now shows correct answer... after 6 min... Phew!!!

why is my submission taking

kaushikdr @ 1 Sep 2012 04:08 PM
why is my submission taking so much time to show the result?

My code is perfectly running

madhur13490 @ 1 Sep 2012 04:28 PM
My code is perfectly running and showing correct answers for all cases at my end but your server is showing wrong answer...any suggestions admin?

my input and output are

krutik_jayswal @ 1 Sep 2012 05:37 PM
my input and output are correct still its showing runrime error.. can anyone tell me why this in happning?

any tricky test cases?

abhinav1592 @ 1 Sep 2012 05:50 PM
any tricky test cases?

using delete[ ] in my program

kp25 @ 1 Sep 2012 06:18 PM
using delete[ ] in my program caused SIGABRT error, but once i removed delete[ ] , it got accepted..! why..?

can anybody tell me how to

goelanshul2011 @ 1 Sep 2012 07:13 PM
can anybody tell me how to give he output for 2 test cases.I mean how to separate output for more than 2 test cases.

is the name of input file is

saurav431 @ 1 Sep 2012 08:31 PM
is the name of input file is input.txt

hey @admin plz reply how to

shiv_bha @ 1 Sep 2012 08:38 PM
hey @admin plz reply how to show o/p in more than 1 test case

@admin: what is the memory

shivamlearning @ 1 Sep 2012 09:11 PM
@admin: what is the memory limit for the arrays for this problem?

Is the time limit not

tanujrastogi @ 1 Sep 2012 09:21 PM
Is the time limit not applicble in this contest?? Even my friend's TEN second solution was accepted and he was awarded one score!

i am new here....i have coded

dexterromio123 @ 1 Sep 2012 09:27 PM
i am new here....i have coded this peroblem and it is running fine at my side...i want to know how the input are given to code during checking...means admin provide input ar we have to consider some test cases in code??

what is the memory limit for

grishmashah @ 1 Sep 2012 11:02 PM
what is the memory limit for the arrays for this problem.plz reply me

Anyone pls reply how the

sharod @ 1 Sep 2012 11:11 PM
Anyone pls reply how the output should look for more than one test case!!!

output for more than one

georgemickael @ 1 Sep 2012 11:38 PM
output for more than one testcases ? please. my logic and program is correct but it is showing wron output ....

@admin please tell me the

upen_jat @ 1 Sep 2012 11:43 PM
@admin please tell me the time complexity of this code

@admin i solved this question

dawdler @ 2 Sep 2012 01:27 AM
@admin i solved this question and soln got accepted but why i didn't get any point for this question???? pls reply

if S[i] is -ve no then what

ananta @ 2 Sep 2012 03:41 AM
if S[i] is -ve no then what to do. if t >1 and 2> N >5000 then what to do sir..........please reply

@mi_ke: there is a

shivamlearning @ 2 Sep 2012 07:46 AM
@mi_ke: there is a restriction that 1<= S[i]<=1000000000 So i think S[i] is never negative.

Can anyone please tell me how

cnatka @ 2 Sep 2012 08:17 AM
Can anyone please tell me how to give output, is it just to print or some other way we have to generate the output??

Is anyone knows using which

kaveen_7 @ 2 Sep 2012 08:37 AM
Is anyone knows using which tool they are testing our program??

How do you do a next line in

mattbrotz @ 2 Sep 2012 09:18 AM
How do you do a next line in PHP?

why am i getting wring ans on

vermansit @ 2 Sep 2012 02:40 PM
why am i getting wring ans on code chef , my programme is running completely f9 on my compiler

Time limit for the above

procoder_369 @ 2 Sep 2012 02:51 PM
Time limit for the above problem is 3s. WHY A CODE IS ACCEPTED IF IT RUNS IN 10 SECS?? ANYONE PLZ ANSWER

getting runtime error , how

eragon12 @ 2 Sep 2012 03:57 PM
getting runtime error , how to check wheather how much memory is using by my program.

how to check runtime error

myway @ 2 Sep 2012 08:35 PM
how to check runtime error

my prog in gcc compiler run

codder @ 2 Sep 2012 10:18 PM
my prog in gcc compiler run correctly...but here it shows run time error...y..??

@Admin Please provide some

dark666 @ 2 Sep 2012 11:30 PM
@Admin Please provide some inputs that you are running in the program. My program is giving run-time error whereas I have maintained all possible constraints

my code is running on my

gaurav451404 @ 3 Sep 2012 01:02 AM
my code is running on my compiler,but here it shows compilation error...

@Admin : Please clarify if

kamini_kashyap @ 3 Sep 2012 03:05 PM
@Admin : Please clarify if the output for more than one test case has to be printed on single line or new line each. Also please specify how many testcases the user has failed or passed. Bcoz here ppl are confused whether the code is wrong or output format is wrong for all cases.

@admin: plz specify the test

himjones @ 3 Sep 2012 05:03 PM
@admin: plz specify the test cases in which the program gives a wrong answer, becoz i m getting the correct output as per the specified input, however here i m getting a message of wrong answer........plz help

@admin How do I know the test

akhileshchg @ 3 Sep 2012 06:00 PM
@admin How do I know the test cases in which my code fails. because when I tried testing, my code worked fine.. but when i submit it is saying wrong answer

@admin my program is

spider3091 @ 3 Sep 2012 11:06 PM
@admin my program is satisfying ur test case at my side but it is giving run tm error why is it so pls do reply.

@spider3091 and others with

f1zz0_13 @ 5 Sep 2012 02:40 AM
@spider3091 and others with such an issue : Try to figure out different critical test cases on your own where your code might go wrong. I guess learning how to figure out the test cases is as important as the coding itself. I was stuck like you are now, but after some 5 minutes of thought have now figured out where I was wrong. Was a really stupid error on my part.

can any one please tell me

nyfer @ 5 Sep 2012 12:15 PM
can any one please tell me how is the output given for more than one test cases

can any1 say me whats the

kpinturaj @ 5 Sep 2012 05:09 PM
can any1 say me whats the format specifier for long long int in c???

can any1 tell me if there has

neo80 @ 5 Sep 2012 07:38 PM
can any1 tell me if there has to be a input file.txt ?

What does test case here does

neo80 @ 5 Sep 2012 07:42 PM
What does test case here does ?

How to give output in the

gauravwdhwa @ 6 Sep 2012 12:11 PM
How to give output in the file like: Case 1: 3 or 3

what's the input file name

santhoshsd @ 6 Sep 2012 12:16 PM
what's the input file name ? I am getting a Runtime Error.

ha ha ha...1st attempt (my

adil9 @ 6 Sep 2012 11:49 PM
ha ha ha...1st attempt (my code took approx 9.6 secs still accepted) next attempt (my code took 5.1 secs still accepted) 3rd attempt (my code took 0.31 secs now I am satisfied) :) but @admin plz fix this problem because this will surely disturb the statistics of rankings...

Compiler not accepting abs()

abhi_ignite @ 7 Sep 2012 11:08 PM
Compiler not accepting abs() function in c++ code.. I have included math.h lib it's not accepting. Admin help

run time error :( my program

yks01247 @ 8 Sep 2012 12:03 PM
run time error :( my program works perfectly fine in my pc and the constraints of variables are also checked :/

My code is perfectly running

maheshksd @ 8 Sep 2012 12:54 PM
My code is perfectly running and showing correct answers for all cases at my end but your server show "wrong answer". then i checked and corrected now "Accepted",i am happy now.

its giving run time error any

sahil_ratra @ 9 Sep 2012 05:30 PM
its giving run time error any solutions?? its working fyn on my pc.

@admin: can i get some more

india_gagan @ 9 Sep 2012 09:40 PM
@admin: can i get some more test cases?

@admin or can anyone tell me

dawdler @ 11 Sep 2012 03:04 PM
@admin or can anyone tell me that i solved this problem but didn't get any points.why is it so?

...

lashabuxo @ 11 Sep 2012 03:20 PM
...

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.