#P3534. Gentle Excavation Planning

    ID: 16788 Type: Default 1000ms 256MiB

Gentle Excavation Planning

Gentle Excavation Planning

Byteasar is stranded in the Byteotian Desert along the Dry River. With the river dry and his water supplies depleted, his only hope is to dig a well deep enough to reach the water level. However, he can only dig a limited amount before his strength fails. Moreover, he wants to keep the excavation slope as gentle as possible to avoid a deadly landslide.

You are given the depth of the water level D, his maximum digging capacity (strength) S, and a topographic map of the river bed indicating the elevation at N positions. At position i (1-indexed) the elevation is a_i. In order to reach water at position i, Byteasar must dig an amount equal to

\(d_i = D - a_i\)

provided \(a_i \leq D\).

The digging at position i is feasible only if \(d_i \leq S\). Among all feasible positions, Byteasar wishes to choose the one that minimizes \(d_i\) (i.e. where the excavation is as gentle as possible). If there are multiple positions with the same \(d_i\), choose the one with the smallest index. If no position can be excavated within his strength, output impossible.

Your task is to help Byteasar determine where he should dig. If a feasible position exists, output the 1-indexed position and the required digging amount separated by a space. Otherwise, output impossible.

inputFormat

The input consists of two lines.

The first line contains three integers:

  • N (the number of positions in the topographic map),
  • D (the water level depth), and
  • S (the maximum amount Byteasar can dig).

The second line contains N integers \(a_1, a_2, \ldots, a_N\) representing the elevation at each position.

outputFormat

If there exists a position where the required digging amount \(d_i = D - a_i\) does not exceed \(S\), output two integers separated by a space: the 1-indexed position and \(d_i\). Otherwise, output the string impossible.

sample

5 10 5
6 8 4 9 7
4 1