#P10445. Maximizing Check-ins on a Linear Road

    ID: 12454 Type: Default 1000ms 256MiB

Maximizing Check-ins on a Linear Road

Maximizing Check-ins on a Linear Road

You are given n checkpoints located on an infinite straight road (which we treat as a number line). You start at the origin (i.e. coordinate 0) and the i-th checkpoint is at coordinate xi. In each time unit, you may move at most 1 unit of distance.

Your goal is to sign in at as many different checkpoints as possible and then return to the origin within the time limit. Signing in takes negligible time, and if there are multiple checkpoints at the same location, you may sign in at all of them when you are there.

You are initially given a time limit of m time units. However, there is a twist: at the p-th checkpoint a gift is placed. If you sign in at this checkpoint, your time limit is extended to m+5 time units (note that you may receive the gift after time m, but you must return to the origin by time m+5).

It is known that if the set of visited checkpoints has extreme coordinates L (minimum) and R (maximum), then the minimal route time required to cover them (starting and ending at the origin) is given by:

  • If \(L \ge 0\), the time required is \(2R\).
  • If \(R \le 0\), the time required is \(-2L\).
  • If \(L < 0 < R\), the time required is \(R - L + \min(R, -L)\).

Your task is to determine the maximum number of checkpoints you can sign in at while being able to return to the origin within the corresponding time limit. In doing so, if there are multiple choices achieving the maximum count, you must choose the one whose set of checkpoint indices (when sorted in increasing order) is lexicographically smallest.

inputFormat

The input consists of two lines:

  1. The first line contains three integers \(n\), \(m\), and \(p\).
  2. The second line contains \(n\) integers \(x_1, x_2, \dots, x_n\) representing the coordinates of the checkpoints.

outputFormat

Output two lines:

  1. The first line should contain a single integer representing the maximum number of checkpoints that can be visited.
  2. The second line should contain the visited checkpoint indices (in increasing order, separated by a single space). If no checkpoint can be visited, output an empty line.

sample

5 10 3
-2 1 3 -1 2
4

1 2 4 5

</p>