Under construction

Still being built. Things may change

Post Office 2

Time limit1sMemory limit1024 MB

Summary
Pick P of V village positions on a circular road for post offices so the total distance from each village to its nearest office is minimal.
Level

Medium6 of 10

Topics
Dynamic programming, Array
Solved
No attempts yet

Problem

A circular main road runs around a loop, and V villages are located along it. The circumference of the road is the integer L. In this problem, the road is a circle of integers from 0 to L-1, and each village position is an integer coordinate on the road. Several villages may share the same position. The distance between two villages at coordinates x and y is min⁡(∣x−y∣,L−∣x−y∣)\min(|x - y|, L - |x - y|).

You want to build P post offices where the villages are. Not every village gets one. Choose P of the V villages and build a post office at each chosen position. The goal is to minimize the sum of distances between each village and its nearest post office.

Write a program that reads the village positions and the number P, computes the minimum possible sum of distances from each village to its nearest post office, and prints the positions where the post offices should be built so that this sum is achieved.

Input

The first line contains three integers V, P, and L. (1≤P≤V≤1001 \le P \le V \le 100, 1≤L≤10121 \le L \le 10^{12})

The next line contains V integer coordinates giving the position of each village. The coordinates are sorted in non-decreasing order. Each coordinate is between 0 and L-1, inclusive.

Output

On the first line, print the integer S, the minimum possible sum of distances between each village and its nearest post office.

On the next line, print the P positions of the villages where post offices are built, in non-decreasing order.

Examples2

  1. Example 1

    Input
    10 5 200
    1 2 3 6 7 9 11 22 44 50
    
    Expected output
    9
    2 7 22 44 50
    
  2. Example 2

    Input
    10 5 51
    1 2 3 6 7 9 11 22 44 50
    
    Expected output
    8
    1 6 9 22 44