#C1455. Minimize Maximum Lecture Delay

    ID: 44211 Type: Default 1000ms 256MiB

Minimize Maximum Lecture Delay

Minimize Maximum Lecture Delay

You are given n lectures and a restriction period of k hours during which no lecture may start. Each lecture has an associated delay cost. Your task is to assign each lecture a starting hour such that no lecture begins before hour \(k+1\) and the maximum delay is minimized.

More formally, let \(s_i\) be the starting hour for the \(i\)-th lecture (with \(i\) being its original 1-indexed position). The delay for the \(i\)-th lecture is defined as \(s_i - i\). The objective is to minimize the maximum delay across all lectures, i.e., \[ \min \max_{1 \le i \le n} (s_i-i)\] .

The strategy is to sort the lectures by their delay cost and then assign them consecutively starting from hour \(k+1\). After assignment, the output should report the minimized maximum delay and the schedule of starting hours in the original lecture order.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains two space-separated integers \(n\) and \(k\), where \(n\) is the number of lectures and \(k\) indicates that no lecture can start before hour \(k+1\).
  2. The second line contains \(n\) space-separated integers representing the delay costs of each lecture.

outputFormat

The output is written to standard output (stdout) and consists of two lines:

  1. The first line contains a single integer representing the minimized maximum delay.
  2. The second line contains \(n\) space-separated integers representing the starting hours for each lecture in the original order.
## sample
4 2
1 3 5 7
2

3 4 5 6

</p>