• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
August 06, 2023 |8.9K Views
PROBLEM OF THE DAY: 05/08/2023 | Chocolate Distribution Problem
Description
Discussion

In this video, we are given an array A[ ] of positive integers of size N, where each value represents the number of chocolates in a packet. Each packet can have a variable number of chocolates. There are M students, the task is to distribute chocolate packets among M students such that :
1. Each student gets exactly one packet.
2. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum.

Example 1:

Input:
N = 8, M = 5
A = {3, 4, 1, 9, 56, 7, 9, 12}

Output: 6

Explanation: The minimum difference between maximum chocolates and minimum chocolates is 9 - 3 = 6 by choosing following M packets :{3, 4, 9, 7, 9}.

Give the problem a try before going through the video. All the best!!!

Problem Link: https://practice.geeksforgeeks.org/problems/chocolate-distribution-problem3825/1

Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/91d22e05-5467-47fb-a3e4-13fa836b8670