/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 200 点
問題文
N 人の人が左右一列に並んでいます。左から i 番目 (1\le i\le N) の人を人 i と呼びます。人 i (1\le i\le N) の身長は A_i です。
i=1,2,\ldots,N に対し、人 i より左にいる人であって人 i より身長の高い人が存在するか判定し、存在する場合はその中で番号が人 i に最も近い人を求めてください。
制約
- 1\le N\le 100
- 1\le A_i\le 100
- 入力される値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
N 行出力せよ。
i 行目 (1\le i\le N) には、人 i より左にいる人であって人 i より身長の高い人が存在しない場合は -1 を、存在する場合はその中で番号が人 i に最も近い人の番号を出力せよ。
入力例 1
4 4 3 2 5
出力例 1
-1 1 2 -1
- 人 1 より左側に人はいません。したがって、 1 行目には -1 を出力してください。
- 人 2 より左側にいる人で人 2 より身長が高いのは人 1 のみです。したがって、 2 行目には 1 を出力してください。
- 人 3 より左側にいる人で人 3 より身長が高いのは人 1,2 で、このうち番号が人 3 に最も近いのは人 2 です。したがって、 3 行目には 2 を出力してください。
- 人 4 より左側に人 4 より身長が高い人はいません。したがって、 4 行目には -1 を出力してください。
入力例 2
3 7 7 7
出力例 2
-1 -1 -1
同じ身長の人が複数人いる場合もあります。
入力例 3
6 31 9 17 10 2 9
出力例 3
-1 1 1 3 4 4
Score : 200 points
Problem Statement
There are N people standing in a row from left to right. The i-th person from the left (1\le i\le N) is called person i. The height of person i (1\le i\le N) is A_i.
For each i=1,2,\ldots,N, determine whether there exists a person to the left of person i who is taller than person i, and if so, find the person standing closest to person i among them.
Constraints
- 1\le N\le 100
- 1\le A_i\le 100
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Output N lines.
The i-th line (1\le i\le N) should contain -1 if there is no person to the left of person i who is taller than person i, and otherwise, the number representing the person standing closest to person i among such people.
Sample Input 1
4 4 3 2 5
Sample Output 1
-1 1 2 -1
- There is no person to the left of person 1. Thus, output -1 on the first line.
- Among the people to the left of person 2, only person 1 is taller than person 2. Thus, output 1 on the second line.
- Among the people to the left of person 3, persons 1,2 are taller than person 3, and the person standing closest to person 3 is person 2. Thus, output 2 on the third line.
- There is no person to the left of person 4 who is taller than person 4. Thus, output -1 on the fourth line.
Sample Input 2
3 7 7 7
Sample Output 2
-1 -1 -1
There may be multiple people with the same height.
Sample Input 3
6 31 9 17 10 2 9
Sample Output 3
-1 1 1 3 4 4