Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5765 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4993 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1278 |

@bt8816103042 | 739 |

@rohitanand | 495 |

@codeantik | 479 |

@shalinibhataniya1097 | 472 |

@amrutakashikar2 | 464 |

@thealchemist627 | 456 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@dalwainazism125 | 453 |

@SherlockHolmes3 | 447 |

Complete Leaderboard |

Given an array **A** of positive integers of size **N**, where each value represents number of chocolates in a packet. Each packet can have variable number of chocolates. There are **M** students, the task is to distribute chocolate packets such that :

1. Each student gets one packet.

2. The difference between the number of chocolates given to the students having packet with maximum chocolates and student having packet with minimum chocolates is minimum.

**Input:**

The first line of input contains an integer **T**, denoting the number of test cases. Then **T** test cases follow. Each test case consists of three lines. The first line of each test case contains an integer **N** denoting the number of packets. Then next line contains **N** space separated values of the array A denoting the values of each packet. The third line of each test case contains an integer m denoting the no of students.

**Output:**

For each test case in a new line print the minimum difference.

**Constraints:**

1 <= T <= 100

1 <=N<= 10^{7}

1 <= A_{i} <= 10^{18}

1 <= M <= N

**Example:**

**Input:**

2

8

3 4 1 9 56 7 9 12

5

7

7 3 2 4 9 12 56

3

**Output:**

6

2

**Explanation:
Testcase 1: **The minimum difference between maximum chocolates and minimum chocolates is 9-3=6

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Chocolate Distribution Problem

...