Question: Backtracking: please use C++ and add comments in the code to make it understandable We are given an integer array numbers where numbers[i] is the

Backtracking: please use C++ and add comments in the code to make it understandable

We are given an integer array numbers where numbers[i] is the i-th number. We assign the n numbers to k groups. Each number is assigned to exactly one group. Find the assignment such that the maximum sum of the groups is minimized.

Return the minimum maximum sum.

The input consists of two lines; the second line is the numbers array; the first line has the length of the numbers array n and number of groupsk. Output should be a single number that is the minimum maximum sum among the groups.

Example 1

Input: 3 3 3 2 3 Output: 3 Explanation: Assigning each number to each worker leads to maximum sum 3. No other assignment can have lower maximum sum. 

Example 2

Input: 5 2 1 2 4 7 8 Output: 11 Explanation: Assignment: group 1: 1,2,8, sum: 11 group 2: 4,7, sum: 11 No other assignments can be lower maximum sum. 

Starter Code:

Backtracking: please use C++ and add comments in the code to make

1 #include 2 #include 3 4 int main() 5 { 6 int n, k; 7 scanf("%d %d", &n, &k); 8 int *arr = (int*) malloc(sizeof(int)*n); 9 for(int i=0; i 2 #include 3 4 int main() 5 { 6 int n, k; 7 scanf("%d %d", &n, &k); 8 int *arr = (int*) malloc(sizeof(int)*n); 9 for(int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!