#K73092. Smart Meter Installation Schedule
Smart Meter Installation Schedule
Smart Meter Installation Schedule
In this problem, you are given a sequence of houses, each with its power consumption value. Your task is to determine the minimal installation schedule for smart meters, such that no two adjacent houses have their meters installed on the same day.
The key observation is that for more than one house, installing meters on alternative days (i.e. using indices parity) yields an optimal solution. Formally, if we denote the houses by indices (1, 2, \dots, n), then one optimal schedule is to install meters on days defined by:
[
\text{Day 1 (even-indexed if using 1-based indexing)} = { i \mid i \text{ is odd} }
]
[
\text{Day 2 (odd-indexed)} = { i \mid i \text{ is even} }
]
Note that if there is only one house, a single day is sufficient.
inputFormat
The input is read from standard input (stdin). The first line contains a single integer (n), the number of houses. The second line contains (n) space-separated integers representing the power consumption of each house.
outputFormat
Output to standard output (stdout). The first line should contain the minimal number of days required for the installation. Each of the following lines corresponds to one day and contains the 1-indexed house numbers (separated by a single space) on which the smart meters are installed that day.## sample
5
3 8 4 2 6
2
1 3 5
2 4
</p>