CodeChef: Codechef
Site under maintenance
  • Register
  • Forgot Password?
  • PRACTICE
    • Easy
    • Medium
    • Hard
  • COMPETE
    • August Mini Challenge
    • August Algorithm Challenge
    • July Algorithm Challenge
    • June Algorithm Challenge
    • May Gamers Challenge
  • DISCUSS
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef TechTalks
    • CodeChef Meetups
    • Campus Chapters
    • Host Your Contest
    • User Groups
  • HELP
    • Frequently Asked Questions
    • FAQ for Problem Setters
    • Tutorial: Paying Up
    • Tutorial: Small Factorials
    • Tutorial: Input and Output(I/O)
    • Tutorial: Your First Non-Trivial Problem
  • ABOUT
    • About CodeChef
    • About Directi
    • CEO's Corner
    • Press Room
    • Careers

Home » Problems (medium) » Choosing Cook Off Problems

Choosing Cook Off Problems

Problem code: COOKOFF

  • Submit
  • All submissions

All submissions for this problem are available.

Dave is having trouble choosing problems for the upcoming cook-off. The admins will be mad at him if he doesn't select problems with a gradually increasing level of difficulty. To make his task easier, Dave has assigned a difficulty rating to each problem he has written. A difficulty gap is defined as the absolute difference in difficulty rating between 2 problems, where there is no other problem with a difficulty rating between them. For example, if problems are chosen with difficulty ratings of 4, 7, 13, and 19, then the difficulty gaps are 3, 6, and 6. Dave has already chosen 2 problems for the cook-off, and wants to choose the remaining problems in a way that minimizes the largest difficulty gap.

Input

Input begins with an integer T, the number of test cases. Each test case begins with 4 integers N M C1 C2 on a line. N is the number of problems to choose from (not including the two already chosen problems). M is the number of problems that must be chosen (in addition to the two that have already been chosen). C1 and C2 are the difficulty ratings of the 2 problems that have already been chosen. Following this is a line with exactly N integers, giving the difficulty ratings of the remaining problems. Again, the 2 already chosen problems are not included in the values of N and M. A blank line separates each test case, including a blank line after the number of test cases.

Output

For each test case, output on a single line the minimum possible value of the largest difficulty gap.

Sample Input:

3

3 1 0 100
16 45 61

5 0 50 80
20 40 60 80 100

6 3 0 100
21 64 34 55 64 89

Sample Output:

55
30
34

Contsraints

T≤250
0≤M≤N≤1000
All difficulty ratings are between 0 and 1000000, inclusive.


Date:2010-11-09
Time limit:2s
Source limit:50000B
Languages:All except: TCL


  • Submit

Comments

Loading Comments...

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Loading Submissions...

RECENT ACTIVITY FOR THIS PROBLEM:

Loading Recent Activity...

HELP

Program should read from standard input and write to standard output.

After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

If you are still having problems, see a sample solution here.

  • About CodeChef
  • About Directi
  • CEO's Corner
  • Careers
  • feedback@codechef.com

© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs

Sponsors
The time now is: