Question
/* * A set of K numbers is selected from an given array of N non-negative integers. The score * of a set is calculated
/* * A set of K numbers is selected from an given array of N non-negative integers. The score * of a set is calculated as the the difference between the smallest and the greatest numbers * in the set. Find the set that has the minimum score. * * You are asked to implement the functions main() and findMinScore() as specified below. * * Example: * * For N = 4 and K = 3, * and the array contains: {1, 8, 7, 4} * * All set combinations: * {1, 8, 7} => score is 7 * {1, 8, 4} => score is 7 * {1, 7, 4} => score is 6 * {8, 7, 4} => score is 4 * * Therefore, the min. score is 4. * */ #include
* your implementation of findMinScore(). * */ int main() { ifstream fin("tut01_input.txt"); if (!fin) { cout << "Input file not found."; exit(1); } return 0; }
7 4 3 1 8 7 4 6 4 1 10 11 50 12 13 6 5 1 10 11 50 12 13 6 6 1 10 11 50 12 13 17 7 12 4 7 9 2 23 25 41 30 40 28 42 30 44 48 43 50 1 1 1 3 2 3 3 3 ========================================================================== ====== Below is the description of the input format and expected output. ========================================================================== ====== Input: The first line of the input contains an integer T denoting the number of test cases, followed by T test cases. Each test case has two lines. The first line of a test case contains two integers N and K, which are defined in the problem. The second line of a test case contains N integers for the input array. All integer numbers are separated by a space. Output: Case 1 The min. score is 4 Case 2 The min. score is 3 Case 3 The min. score is 12 Case 4 The min. score is 49 Case 5 The min. score is 10 Case 6 The min. score is 0 Case 7 The min. score is 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started