#C6216. Transform Array

    ID: 49952 Type: Default 1000ms 256MiB

Transform Array

Transform Array

You are given an integer (n) and an array (a) of (n) integers. Your task is to construct a new array (b) of the same length satisfying the following conditions:

  1. For each index (i) (0-indexed), (b[i] \ge a[i] + 1).
  2. The sum of the elements in (b) is exactly (S + n), where (S = \sum_{i=0}^{n-1} a[i]) (i.e. the sum increases by exactly (n)).
  3. No two adjacent elements in (b) are the same (i.e. (b[i] \neq b[i+1]) for all valid (i)).

The intended solution is to construct the array (b) by setting [ b_0 = a_0 + 1 ] and for every (i \ge 1), [ b_i = \max(b_{i-1} + 1,; a_i + 1). ]

This way, all the conditions are naturally satisfied. The problem tests your ability to implement a simple greedy strategy while ensuring the input and output are processed using standard input and output protocols.

inputFormat

The first line contains a single integer (n) ((1 \le n \le 10^5)) representing the number of elements in the array. The second line contains (n) space-separated integers, each representing an element of array (a).

outputFormat

Output a single line with (n) space-separated integers that represent the transformed array (b).## sample

4
1 2 3 4
2 3 4 5