#K81987. Relabel Boxes
Relabel Boxes
Relabel Boxes
You are given ( N ) boxes where each box contains a certain number of cookies. Your task is to compute the new label for each box using the formula:
[
\text{new_label}i = \max{1 \leq j \leq N}(\text{cookies}_j) - \text{cookies}_i
]
for ( i = 1, 2, \dots, N ).
For example, if there are 5 boxes with cookie counts [3, 7, 2, 5, 9], the maximum number of cookies is 9. Thus, the new labels are [9-3, 9-7, 9-2, 9-5, 9-9] which equals to [6, 2, 7, 4, 0].
inputFormat
The input is read from standard input (stdin).
The first line contains an integer ( N ) indicating the number of boxes. The second line contains ( N ) space-separated integers, where the ( i^{th} ) integer represents the number of cookies in the ( i^{th} ) box.
outputFormat
The output should be written to standard output (stdout) as a single line of ( N ) space-separated integers. The ( i^{th} ) integer is the new label for the ( i^{th} ) box, computed using the formula: [ \text{new_label}i = \max{1 \leq j \leq N}(\text{cookies}_j) - \text{cookies}_i ]
sample
1
5
0