Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Aarong is a chain of Bangladeshi department stores and owned by BRAC. It provides the market linkage through different retail outlets. Recently, they have

C++ Aarong is a chain of Bangladeshi department stores and owned by BRAC. It provides the market linkage through different retail outlets. Recently, they have decided to build several storehouse along the highway, each one located at an outlets and supplying several of the outlets with the needed goods. Generally, these storehouses should be placed so that the average distance between a outlet and its assigned storehouse is minimized. You are to write a program that computes the optimal positions and assignments of the storehouses.

To make this more precise, the management of Aarong has issued the following specification: You will be given the positions of n restaurants along the highway as n integers d1 < d2 << dn (these are the distances measured from the companys head outlet, which happens to be at the same highway). Furthermore, a number k (k n) will be given, the number of storehouse to be built.

The k storehouses will be built at the locations of k different restaurants. Each outlet will be assigned to the closest storehouse, from which it will then receive its supplies. To minimize shipping costs, the total distance sum, defined as must be as small as possible.

Write a program that computes the positions of the k storehouses, such that the total distance sum is minimized. 

Input Format

The input file contains several descriptions of Aarong chains. Each description starts with a line containing the two integers n and k. Following this will n lines containing one integer each, giving the positions di of the restaurants, ordered increasingly.

The input file will end with a case starting with n = k = 0. This case should not be processed.

Constraints

1 n 200

1 k 30

k n.

Output Format

For each chain, first output the number of the chain. Then output an optimal placement of the storehouse as follows: for each storehouse output a line containing its position and the range of outlets it serves. If there is more than one optimal solution, output any of them. After the storehouse descriptions output a line containing the total distance sum, as defined in the problem text. Output a blank line after each test case.

Sample Input 0

6 3 5 6 12 19 20 27 0 0 

Sample Output 0

Chain 1 Total distance sum = 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2018 Dublin Ireland September 10 14 2018 Proceedings Part 1 Lnai 11051

Authors: Michele Berlingerio ,Francesco Bonchi ,Thomas Gartner ,Neil Hurley ,Georgiana Ifrim

1st Edition

3030109240, 978-3030109240

More Books

Students also viewed these Databases questions

Question

Connect with business communities

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago

Question

2. How much time should be allocated to the focus group?

Answered: 1 week ago

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago