Can you find the sum
Description
Teena is very good at competitive programming, she solved enough problems on arrays and her friend wants to test her knowledge in arrays, so gave her following task :
- The problem is given an array A having N integers, for each element i (1 <= i <= N), find x+y where x is the largest number less than i such that A[x]>A[i] and y is the smallest number greater than i such that A[y]>A[i].
- If there is no x < i such that A[x]>A[i], then take x=−1. Similarly, if there is no y>i such that A[y]>A[i], then take y=−1.
Input
Input Format
First line consists of a single integer denoting N.
Second line consists of N space separated integers denoting the array A.
Constraints
1 <= N <= 10^6
1 <= A[i] <= 10^9
Output
Print N space separated integers, denoting x+y for each i
Hint
Sample 1 Explanation
Values of x for each i: -1,1,2,2,4
Values of y for each i: -1,-1,4,-1,-1
Answer :
Comments
Post a Comment