{"id":"94b45e47-a2ed-40da-a583-4ca7ae0dcc49","name":"Chocolate Distribution","description":"1. 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 :\r\n2. Each student gets exactly one packet.\r\n3. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 10^5\r\n1 &lt;= Ai &lt;= 10^9\r\n1 &lt;= M &lt;= N","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nint chocolatedistribution(vector<int> &arr){\r\n // write your code here\r\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int find(int[]arr, int n, int m) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n //input work\r\n int n = scn.nextInt();\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int m = scn.nextInt();\r\n int ans = find(arr, n, m);\r\n\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"medium","sampleInput":"8\r\n3 4 1 9 56 7 9 12\r\n5","sampleOutput":"6","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"a8ed807e-48b1-4534-99c6-5025a0227a76","name":"Chocolate Distribution","slug":"chocolate-distribution","type":1}],"next":{"id":"6e98a990-0338-4828-8e7f-81dee28c05b6","name":"Chocolate Distribution","type":3,"slug":"chocolate-distribution"},"prev":{"id":"34fdeaf4-9e8e-40f8-bcde-1f8c00c1f56a","name":"Median Of Two Sorted Arrays MCQ","type":0,"slug":"median-of-two-sorted-arrays-mcq"}}}

Chocolate Distribution

1. 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 : 2. Each student gets exactly one packet. 3. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum.

{"id":"94b45e47-a2ed-40da-a583-4ca7ae0dcc49","name":"Chocolate Distribution","description":"1. 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 :\r\n2. Each student gets exactly one packet.\r\n3. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum.","inputFormat":"Input is managed for you","outputFormat":"Output is managed for you","constraints":"1 &lt;= N &lt;= 10^5\r\n1 &lt;= Ai &lt;= 10^9\r\n1 &lt;= M &lt;= N","sampleCode":{"cpp":{"code":"#include <iostream>\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nint chocolatedistribution(vector<int> &arr){\r\n // write your code here\r\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int find(int[]arr, int n, int m) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n public static void main(String[]args) {\r\n Scanner scn = new Scanner(System.in);\r\n //input work\r\n int n = scn.nextInt();\r\n int[]arr = new int[n];\r\n\r\n for (int i = 0; i < n; i++) {\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n int m = scn.nextInt();\r\n int ans = find(arr, n, m);\r\n\r\n System.out.println(ans);\r\n }\r\n}"},"python":{"code":"def main():\r\n pass\r\nif_name_=='__main__':\r\n main()"}},"points":10,"difficulty":"medium","sampleInput":"8\r\n3 4 1 9 56 7 9 12\r\n5","sampleOutput":"6","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"a8ed807e-48b1-4534-99c6-5025a0227a76","name":"Chocolate Distribution","slug":"chocolate-distribution","type":1}],"next":{"id":"6e98a990-0338-4828-8e7f-81dee28c05b6","name":"Chocolate Distribution","type":3,"slug":"chocolate-distribution"},"prev":{"id":"34fdeaf4-9e8e-40f8-bcde-1f8c00c1f56a","name":"Median Of Two Sorted Arrays MCQ","type":0,"slug":"median-of-two-sorted-arrays-mcq"}}}
plane

Editor


Loading...

Chocolate Distribution

medium

1. 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 : 2. Each student gets exactly one packet. 3. The difference between maximum number of chocolates given to a student and minimum number of chocolates given to a student is minimum.

Constraints

1 <= N <= 10^5 1 <= Ai <= 10^9 1 <= M <= N

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

8 3 4 1 9 56 7 9 12 5

Sample Output

6

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode