#C6275. Difference to the Right
Difference to the Right
Difference to the Right
You are given a list of n integers. For each element ai (except the last one), compute the value:
$$ result[i] = a_i - \min\{a_{i+1}, a_{i+2}, \dots, a_n\} $$
For the last element, simply output it unchanged. This problem tests your ability to process arrays and maintain a running minimum from the right.
Example:
Input: 6 4 2 6 3 5 1 Output: 3 1 5 2 4 1
Here, for the first element 4, the minimum of elements to its right is 1, so the result is 4 - 1 = 3, and so on.
inputFormat
The first line contains a single integer n (the number of elements in the array). The second line contains n space-separated integers representing the array.
outputFormat
Output a single line containing n space-separated integers representing the resulting array after computing the differences as described.
## sample6
4 2 6 3 5 1
3 1 5 2 4 1
</p>